Compare commits
No commits in common. 'master' and 'incorrect_closing_investigation' have entirely different histories.
master
...
incorrect_
8 changed files with 55 additions and 335 deletions
@ -1,52 +0,0 @@ |
||||
package gameServer |
||||
|
||||
const ( |
||||
Auth string = "Auth" |
||||
Message string = "Message" |
||||
PlayerAction string = "PlayerAction" |
||||
System string = "System" |
||||
Lobby string = "Lobby" |
||||
) |
||||
|
||||
const ( |
||||
OK int = 200 |
||||
|
||||
LobbyListRequest int = 201 |
||||
LobbyListAnswer int = 202 |
||||
|
||||
BadRequest int = 400 |
||||
Forbidden int = 403 |
||||
Unauthorized = 401 |
||||
|
||||
InternalServerError int = 500 |
||||
) |
||||
|
||||
/* |
||||
Status: |
||||
200 - OK |
||||
201 - Lobby List Request |
||||
202 - Lobby List Answer |
||||
|
||||
|
||||
400 - Bad request |
||||
403 - Forbidden |
||||
401 - Unauthorized |
||||
|
||||
500 - Internal server error |
||||
|
||||
*/ |
||||
|
||||
type Packet struct { |
||||
Type string "json:`Type`" |
||||
Status int "json:`Status`" |
||||
Message interface{} "json:`Message`" |
||||
} |
||||
|
||||
type AuthMsg struct { |
||||
Login string "json:`Login`" |
||||
Password string "json:`Password`" |
||||
} |
||||
|
||||
type LobbyList struct { |
||||
Lobbies []Room "json:`Lobbies`" |
||||
} |
@ -1,123 +0,0 @@ |
||||
package gameServer |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
|
||||
"github.com/gorilla/websocket" |
||||
) |
||||
|
||||
type Player struct { |
||||
Name string `json:"Name"` |
||||
Password string `json:"Password"` |
||||
|
||||
//Connection
|
||||
Conn *websocket.Conn |
||||
|
||||
AuthString string `json:"AuthString"` |
||||
|
||||
Level string `json:"Level"` // hidden from user, for balancing purposes
|
||||
|
||||
Kills int `json:"Kills"` |
||||
Killed int `json:"Killed"` |
||||
|
||||
Won int `json:"Won"` |
||||
Lost int `json:"Lost"` |
||||
WinRate int `json:"WinRate"` |
||||
|
||||
Health int `json:"Health"` |
||||
|
||||
Authed bool `json:"Authed"` |
||||
|
||||
GS *GameServer `json:"GS"` |
||||
} |
||||
|
||||
func (pc *Player) Receiver() { |
||||
for { |
||||
_, message, err := pc.Conn.ReadMessage() |
||||
if err != nil { |
||||
fmt.Println("pc err: " + err.Error()) |
||||
} |
||||
|
||||
var msg Packet |
||||
err = json.Unmarshal(message, &msg) |
||||
if err != nil { |
||||
fmt.Println("pc err: " + err.Error()) |
||||
} |
||||
|
||||
if !pc.Authed && msg.Type != Auth { |
||||
reply := Packet{ |
||||
Type: System, |
||||
Status: 401, |
||||
Message: nil, |
||||
} |
||||
|
||||
authRequired, err := json.Marshal(reply) |
||||
if err != nil { |
||||
fmt.Println("pc err: " + err.Error()) |
||||
} |
||||
pc.Conn.WriteMessage(websocket.TextMessage, authRequired) |
||||
|
||||
//Stop processing the packet of unauthed connection
|
||||
return |
||||
} |
||||
|
||||
switch msg.Type { |
||||
case Auth: |
||||
pc.Auth(msg) |
||||
case Message: |
||||
|
||||
case PlayerAction: |
||||
pc.PlayerAction(msg) |
||||
case System: |
||||
|
||||
case Lobby: |
||||
pc.Lobby(msg) |
||||
default: |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
//TODO
|
||||
func (pc *Player) Auth(p Packet) (pr Packet) { |
||||
// FOR DEV PURPOSES ONLY
|
||||
// This function meant to become an authentication function!
|
||||
pReply := Packet{ |
||||
Type: Auth, |
||||
Status: 200, |
||||
Message: nil, |
||||
} |
||||
|
||||
fmt.Println("Auth successful") |
||||
pc.Authed = true |
||||
|
||||
return pReply |
||||
} |
||||
|
||||
func (pc *Player) Lobby(p Packet) { |
||||
switch p.Status { |
||||
case LobbyListRequest: // Lobby list request
|
||||
p.Message = pc.GS.Lobbies |
||||
p.Status = LobbyListAnswer |
||||
p.Type = Lobby |
||||
|
||||
pMarshall, err := json.Marshal(p) |
||||
if err != nil { |
||||
fmt.Println("pc.Lobby: " + err.Error()) |
||||
} |
||||
pc.Conn.WriteMessage(websocket.TextMessage, pMarshall) |
||||
|
||||
default: |
||||
fmt.Println("player unsupported status") |
||||
} |
||||
|
||||
} |
||||
|
||||
func (pc *Player) ReceivedMessage(p Packet) { |
||||
|
||||
} |
||||
|
||||
func (pc *Player) PlayerAction(p Packet) { |
||||
|
||||
} |
@ -0,0 +1,24 @@ |
||||
package player |
||||
|
||||
import "github.com/gorilla/websocket" |
||||
|
||||
type Player struct { |
||||
Name string `json:"Name"` |
||||
Password string `json:"Password"` |
||||
|
||||
//Connection WS variable TODO
|
||||
Conn *websocket.Conn |
||||
|
||||
AuthString string `json:"AuthString"` |
||||
|
||||
Level string `json:"Level"` // hidden from user, for balancing purposes
|
||||
|
||||
Kills int `json:"Kills"` |
||||
Killed int `json:"Killed"` |
||||
|
||||
Won int `json:"Won"` |
||||
Lost int `json:"Lost"` |
||||
WinRate int `json:"WinRate"` |
||||
|
||||
Health int `json:"Health"` |
||||
} |
@ -1,4 +1,4 @@ |
||||
package gameServer |
||||
package room |
||||
|
||||
import "testing" |
||||
|
Loading…
Reference in new issue