Compare commits
No commits in common. 'f22ef27ea15355c3bf3ce10edd99a39d12885a0e' and '4f965ddefb7c6f0d4ed921cdf137ebdc7418a7a5' have entirely different histories.
f22ef27ea1
...
4f965ddefb
7 changed files with 33 additions and 192 deletions
@ -1,24 +1,13 @@ |
|||||||
package messages |
package messages |
||||||
|
|
||||||
|
/* |
||||||
const ( |
const ( |
||||||
Auth string = "Auth" |
|
||||||
Message string = "Message" |
Message string = "Message" |
||||||
PlayerAction string = "PlayerAction" |
PlayerAction string = "PlayerAction" |
||||||
System string = "System" |
System string = "System" |
||||||
) |
) |
||||||
|
|
||||||
/* |
type PlayerMessage struct { |
||||||
|
|
||||||
|
|
||||||
*/ |
|
||||||
|
|
||||||
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`" |
|
||||||
} |
} |
||||||
|
*/ |
||||||
|
@ -1,59 +0,0 @@ |
|||||||
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) |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue