diff --git a/player.go b/player.go index 2cd3c1d..0045b49 100644 --- a/player.go +++ b/player.go @@ -48,3 +48,13 @@ func makePlayer(ws *websocket.Conn) *Player { players = append(players, player) return player } + +func getPlayer(nickname string) *Player { + for _, player := range players { + if player.Nickname == nickname { + return player + } + } + + return nil +} diff --git a/wshandler.go b/wshandler.go index 3fddb11..24df13d 100644 --- a/wshandler.go +++ b/wshandler.go @@ -194,6 +194,16 @@ func WsHandler(ws *websocket.Conn) { reply("ok", room.ID) }) + handleCommand("sendchat", 2, func() { //HC [person, msg] ok [] error [err] + other := getPlayer(msg.Arguments[0]) + if other == nil { + reply("error", "player-not-found", msg.Arguments[0]) + } + + other.Conn.Send("chatmessage", player.Nickname, other.Nickname, msg.Arguments[1]) + + reply("ok") + }) handleRoomCommand("sendroomchat", 1, func() { //HC [msg] ok [] notifyOthers("chatmessage", player.Nickname, currentRoom.ID, msg.Arguments[0]) reply("ok")