Merged room and player into gameServer. First communication testing. Stable release with communication at a start
parent
f22ef27ea1
commit
c367bf5381
7 changed files with 131 additions and 84 deletions
@ -1,24 +0,0 @@ |
||||
package messages |
||||
|
||||
const ( |
||||
Auth string = "Auth" |
||||
Message string = "Message" |
||||
PlayerAction string = "PlayerAction" |
||||
System string = "System" |
||||
) |
||||
|
||||
/* |
||||
|
||||
|
||||
*/ |
||||
|
||||
type PlayerMsg struct { |
||||
Type string "json:`Type`" |
||||
Status int "json:`Status`" |
||||
Message interface{} "json:`Message`" |
||||
} |
||||
|
||||
type AuthMsg struct { |
||||
Login string "json:`Login`" |
||||
Password string "json:`Password`" |
||||
} |
@ -0,0 +1,52 @@ |
||||
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,4 +1,4 @@ |
||||
package room |
||||
package gameServer |
||||
|
||||
import "testing" |
||||
|
@ -1,47 +0,0 @@ |
||||
package player |
||||
|
||||
import ( |
||||
"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"` |
||||
} |
||||
|
||||
func (pc *Player) Receiver() { |
||||
for { |
||||
|
||||
fmt.Println("ticker") |
||||
|
||||
_, command, err := pc.Conn.ReadMessage() |
||||
|
||||
if err != nil { |
||||
fmt.Println("pc err: " + err.Error()) |
||||
} |
||||
|
||||
pc.Conn.WriteMessage(websocket.TextMessage, []byte("otvet")) |
||||
fmt.Println(command) |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue