Fix: destroy problem

This commit is contained in:
2020-05-31 17:16:54 +08:00
parent be7d3032f7
commit 37da74f40b
5 changed files with 16 additions and 18 deletions
+4 -6
View File
@@ -88,12 +88,10 @@ func (m *ConnManager) Broadcaster() {
for _, conn := range m.conns {
conn.WriteJSON(msg)
}
case msg := <-m.exitCh:
if msg {
log.Println("broadcaster exit")
m.destroyCh <- m.roomID
return
}
case _ = <-m.exitCh:
log.Println("broadcaster exit")
m.destroyCh <- m.roomID
return
}
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ func GetHall() *Hall {
}
func NewHall(maxRoomSize int) *Hall {
hall:=Hall{maxRoomSize: maxRoomSize, rooms: map[int]*Room{}, players: map[int]int{}, destroyCh: make(chan int)}
hall := Hall{maxRoomSize: maxRoomSize, rooms: map[int]*Room{}, players: map[int]int{}, destroyCh: make(chan int)}
go hall.roomController()
return &hall
}
+2 -2
View File
@@ -41,7 +41,7 @@ func RoomCreateHandler(writer http.ResponseWriter, request *http.Request) {
}
userID := msg.UserID
PassWord := msg.Passwd
GameRule:=msg.GameRule
GameRule := msg.GameRule
r := getRuleByName(GameRule)
roomID := container.GetHall().CreateRoom(userID, PassWord, r)
if roomID == -1 {
@@ -50,7 +50,7 @@ func RoomCreateHandler(writer http.ResponseWriter, request *http.Request) {
writer.Write(j)
return
}
log.Print("user[", userID, "] created room: ", roomID, " with password[", PassWord, "], rule:[",GameRule,"]")
log.Print("user[", userID, "] created room: ", roomID, " with password[", PassWord, "], rule:[", GameRule, "]")
j, _ := json.Marshal(createSuccessMsg(roomID))
writer.Write(j)
}
+7 -7
View File
@@ -5,10 +5,10 @@ import _ "github.com/jinzhu/gorm/dialects/postgres"
type Record struct {
gorm.Model
RoomNumber int
Password string
UserID0 int
UserID1 int
UserID2 int
UserID3 int
}
RoomNumber int
Password string
UserID0 int
UserID1 int
UserID2 int
UserID3 int
}
+2 -2
View File
@@ -112,10 +112,10 @@ func TestJinzhouRule_CanWin(t *testing.T) {
model.Tile{2, 6},
false}, //缺门
{[]model.Tile{{0, 1}, {0, 1},
{0, 4}, {0, 4}, {0, 4},
{0, 4}, {0, 4}, {0, 4},
{0, 6}, {0, 8},
{1, 5}, {1, 6}, {1, 7},
{2,9},{2,9},{2,9}},
{2, 9}, {2, 9}, {2, 9}},
[]model.ShownTile{},
model.Tile{0, 7},
true},