Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions game/cards/dm03/cyber_lord.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Shtra(c *match.Card) {
false,
).Map(func(c *match.Card) {
c.Player.MoveCard(c.ID, match.MANAZONE, match.HAND, card.ID)
ctx.Match.ReportActionInChat(card.Player, fmt.Sprintf("%s was moved to %s's manazone from their hand by Shtra", c.Name, c.Player.Username()))
ctx.Match.ReportActionInChat(card.Player, fmt.Sprintf("%s was moved to %s's hand from their manazone by Shtra", c.Name, c.Player.Username()))
})

ctx.Match.Wait(card.Player, "Waiting for your opponent to make an action")
Expand All @@ -64,7 +64,7 @@ func Shtra(c *match.Card) {
false,
).Map(func(c *match.Card) {
c.Player.MoveCard(c.ID, match.MANAZONE, match.HAND, card.ID)
ctx.Match.ReportActionInChat(ctx.Match.Opponent(card.Player), fmt.Sprintf("%s was moved to %s's manazone from their hand by Shtra", c.Name, c.Player.Username()))
ctx.Match.ReportActionInChat(ctx.Match.Opponent(card.Player), fmt.Sprintf("%s was moved to %s's hand from their manazone by Shtra", c.Name, c.Player.Username()))
})

}))
Expand Down
2 changes: 1 addition & 1 deletion game/cards/promo/armored_dragon.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func StarCryDragon(c *match.Card) {
return
}

if event, ok := ctx.Event.(*match.GetPowerEvent); ok && event.Card.ID != card.ID {
if event, ok := ctx.Event.(*match.GetPowerEvent); ok && event.Card.Player == card.Player && event.Card.ID != card.ID {

if event.Card.HasFamily(family.ArmoredDragon) {
event.Power += 3000
Expand Down
20 changes: 18 additions & 2 deletions game/match/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -2006,3 +2007,18 @@ func (m *Match) handleAdminMesseges(message string, user db.User) {

}
}

func (m *Match) handleMessages(message string) {

currentPlayer := m.CurrentPlayer().Player
Copy link
Owner

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oversight.

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()))
Copy link
Owner

Choose a reason for hiding this comment

The 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


}
}
Loading