-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resign button. #309
base: master
Are you sure you want to change the base?
Add resign button. #309
Changes from 4 commits
105bfcc
f603663
484337f
74ffcfb
64be7b2
c5fc7af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1407,7 +1407,8 @@ func (m *Match) Parse(s *server.Socket, data []byte) { | |
return | ||
} | ||
|
||
m.handleAdminMesseges(msg.Message, s.User) | ||
m.handleMessages(msg.Message) | ||
m.handleAdminMessages(msg.Message, s.User) | ||
|
||
if s.User.Chatblocked { | ||
s.Send(&server.ChatMessage{ | ||
|
@@ -1919,7 +1920,7 @@ func (p *PlayerReference) Dispose() { | |
} | ||
} | ||
|
||
func (m *Match) handleAdminMesseges(message string, user db.User) { | ||
func (m *Match) handleAdminMessages(message string, user db.User) { | ||
|
||
hasRights := false | ||
|
||
|
@@ -2006,3 +2007,18 @@ func (m *Match) handleAdminMesseges(message string, user db.User) { | |
|
||
} | ||
} | ||
|
||
func (m *Match) handleMessages(message string) { | ||
|
||
currentPlayer := m.CurrentPlayer().Player | ||
msgParts := strings.Split(message, " ") | ||
if len(msgParts) < 1 { | ||
return | ||
} | ||
|
||
switch msgParts[0] { | ||
case "/quit": | ||
m.End(m.Opponent(currentPlayer), fmt.Sprintf("%s won by opponent resigning.", m.Opponent(currentPlayer).Username())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since incoming chat events are of ParallelEvent type they will be handled in a separate non-blocking goroutine than the match logic itself which might cause some panics during runtime as it can dispose of the match and players (which closes channels and nils most slices and pointers) at the same time as some match logic is executed which is trying to use those references Maybe a separate Forfeit event of SequentialEvent type could be created and sent by the client, or some other way to make sure the m.End call is called from inside the blocking eventloop queue |
||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this make it so you can win by typing /quit during the opponent's turn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oversight.