Compare commits
2 commits
4f3ad1d63a
...
be83334e3a
Author | SHA1 | Date | |
---|---|---|---|
be83334e3a | |||
f8b5dbfc17 |
1 changed files with 48 additions and 1 deletions
|
@ -70,13 +70,60 @@ func (d *draftBot) handleMessage(roomid string, msg room.Message) {
|
||||||
if !ok {
|
if !ok {
|
||||||
// Room does not have a currently running session, ignore unless it's the owner asking for specific stuff
|
// Room does not have a currently running session, ignore unless it's the owner asking for specific stuff
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if player is in the draft
|
// Check if player is in the draft
|
||||||
player, ok := session.Players[msg.From]
|
player, ok := session.Players[msg.From]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Player not in draft, are they asking to join?
|
// Player not in draft, are they asking to join?
|
||||||
//TODO
|
switch msg.Type {
|
||||||
|
// Player is asking to join
|
||||||
|
case "join":
|
||||||
|
// Players can only join if session didn't start yet
|
||||||
|
if session.started {
|
||||||
|
d.sendMessage(roomid, room.Message{
|
||||||
|
To: msg.From,
|
||||||
|
Type: "session-already-started",
|
||||||
|
Message: "You can't join a running session",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there are still open slots
|
||||||
|
if len(session.Players)+1 > len(session.Pod.Players) {
|
||||||
|
d.sendMessage(roomid, room.Message{
|
||||||
|
To: msg.From,
|
||||||
|
Type: "session-full",
|
||||||
|
Message: "There aren't any spots left",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add player to the list
|
||||||
|
session.Players[msg.From] = nil
|
||||||
|
|
||||||
|
d.sendMessage(roomid, room.Message{
|
||||||
|
Channel: "draft",
|
||||||
|
Type: "player-joined-session",
|
||||||
|
Data: msg.From,
|
||||||
|
Message: fmt.Sprintf("%s joined the draft session (%d players, %d missing)", msg.From, len(session.Players), len(session.Pod.Players)-len(session.Players)),
|
||||||
|
})
|
||||||
|
|
||||||
|
// Player wants something else
|
||||||
|
default:
|
||||||
|
// Tell them can either join or GTFO
|
||||||
|
d.sendMessage(roomid, room.Message{
|
||||||
|
To: msg.From,
|
||||||
|
Type: "not-joined-err",
|
||||||
|
Data: "not joined",
|
||||||
|
Message: "You must join the session to do anything",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
|
|
Loading…
Reference in a new issue