You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.1 KiB
59 lines
1.1 KiB
package gameServer |
|
|
|
import ( |
|
"encoding/json" |
|
"fmt" |
|
|
|
messages "daydev.org/shipsgs/internal/Messages" |
|
"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 { |
|
_, command, err := pc.Conn.ReadMessage() |
|
if err != nil { |
|
fmt.Println("pc err: " + err.Error()) |
|
} |
|
|
|
if pc.Authed == false { |
|
reply := messages.PlayerMsg{ |
|
Type: messages.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) |
|
} |
|
|
|
fmt.Println(command) |
|
} |
|
}
|
|
|