diff --git a/internal/gameServer/gameServer.go b/internal/gameServer/gameServer.go index f8fea47..a6b9cbb 100644 --- a/internal/gameServer/gameServer.go +++ b/internal/gameServer/gameServer.go @@ -6,7 +6,6 @@ import ( "sync" "daydev.org/shipsgs/internal/config" - "daydev.org/shipsgs/internal/player" "daydev.org/shipsgs/internal/utils" ) @@ -21,10 +20,10 @@ type GameServer struct { currentPlayers int // Storing connected Players - playerConns map[*player.Player]bool + playerConns map[*Player]bool // Notify Game Server a New Player - Connection chan *player.Player + Connection chan *Player //Quit the loops correctly and shut down the Game Server Shutdown chan bool @@ -49,9 +48,9 @@ func (m *GameServer) Init(logger *utils.Logger, config *config.S_Config) { m.currentLobbies = 0 m.currentPlayers = 0 - m.Connection = make(chan *player.Player) + m.Connection = make(chan *Player) - m.playerConns = make(map[*player.Player]bool) + m.playerConns = make(map[*Player]bool) m.WG.Add(2) diff --git a/internal/gameServer/player.go b/internal/gameServer/player.go new file mode 100644 index 0000000..7cc1b86 --- /dev/null +++ b/internal/gameServer/player.go @@ -0,0 +1,59 @@ +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) + } +} diff --git a/internal/server/server.go b/internal/server/server.go index 36e0a8f..a6d85dd 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -7,7 +7,6 @@ import ( "net/http" "daydev.org/shipsgs/internal/gameServer" - "daydev.org/shipsgs/internal/player" "github.com/gorilla/websocket" ) @@ -43,10 +42,12 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) { return } - player := &player.Player{ + player := &gameServer.Player{ Conn: conn, } player.Name = "Yale" + player.Authed = false + player.GS = GS GS.Connection <- player