Example #1
0
func RestoreServemeChecks() {
	var ids []uint
	db.DB.Model(&Lobby{}).Where("state <> ? AND serveme_id <> 0", Ended).Pluck("id", &ids)

	for _, id := range ids {
		lobby, _ := GetLobbyByIDServer(id)
		context := helpers.GetServemeContext(lobby.ServerInfo.Host)
		lobby.ServemeCheck(context)
	}
}
Example #2
0
//Close closes the lobby, which has the following effects:
//
//  All unfilled substitutes for the lobby are "filled" (ie, their filled field is set to true)
//  The corresponding ServerRecord is deleted
//
//If rpc == true, the log listener in Pauling for the corresponding server is stopped, this is
//used when the lobby is closed manually by a player
func (lobby *Lobby) Close(doRPC, matchEnded bool) {
	var count int

	db.DB.Preload("ServerInfo").First(lobby, lobby.ID)
	db.DB.Model(&gameserver.ServerRecord{}).Where("host = ?", lobby.ServerInfo.Host).Count(&count)
	if count != 0 {
		gameserver.PutStoredServer(lobby.ServerInfo.Host)
	}

	lobby.SetState(Ended)
	db.DB.First(lobby).UpdateColumn("match_ended", matchEnded)
	//db.DB.Exec("DELETE FROM spectators_players_lobbies WHERE lobby_id = ?", lobby.ID)
	if doRPC {
		rpc.End(lobby.ID)
	}
	if matchEnded {
		lobby.UpdateStats()
	}
	if lobby.ServemeID != 0 {
		context := helpers.GetServemeContext(lobby.ServerInfo.Host)
		err := context.Delete(lobby.ServemeID, lobby.CreatedBySteamID)
		if err != nil {
			logrus.Error(err)
		}
		if matchEnded {
			time.AfterFunc(10*time.Second, func() {
				lobby.DownloadDemo(context)
			})
		}
	}

	privateRoom := fmt.Sprintf("%d_private", lobby.ID)
	broadcaster.SendMessageToRoom(privateRoom, "lobbyLeft", LobbyEvent{ID: lobby.ID})

	publicRoom := fmt.Sprintf("%d_public", lobby.ID)
	broadcaster.SendMessageToRoom(publicRoom, "lobbyClosed", DecorateLobbyClosed(lobby))

	db.DB.Model(&gameserver.ServerRecord{}).Where("id = ?", lobby.ServerInfoID).Delete(&gameserver.ServerRecord{})
	BroadcastSubList()
	BroadcastLobby(lobby)
	BroadcastLobbyList() // has to be done manually for now
	rpc.FumbleLobbyEnded(lobby.ID)
	lobby.deleteLock()
}
Example #3
0
//Delete removes the lobby object from the database.
//Closed lobbies aren't deleted, this function is used for
//lobbies where the game server had an error while being setup.
func (lobby *Lobby) Delete() {
	var count int

	db.DB.Model(&gameserver.ServerRecord{}).Where("host = ?", lobby.ServerInfo.Host).Count(&count)
	if count != 0 {
		gameserver.PutStoredServer(lobby.ServerInfo.Host)
	}

	if lobby.ServemeID != 0 {
		context := helpers.GetServemeContext(lobby.ServerInfo.Host)
		err := context.Delete(lobby.ServemeID, lobby.CreatedBySteamID)
		for err != nil {
			err = context.Delete(lobby.ServemeID, lobby.CreatedBySteamID)
		}
	}

	db.DB.Delete(lobby)
	db.DB.Delete(&lobby.ServerInfo)

	lobby.deleteLock()
}