示例#1
0
文件: event.go 项目: TF2Stadium/Helen
func playerDisc(steamID string, lobbyID uint) {
	player, _ := playerpackage.GetPlayerBySteamID(steamID)
	lobby, _ := lobbypackage.GetLobbyByID(lobbyID)

	lobby.SetNotInGame(player)

	chat.SendNotification(fmt.Sprintf("%s has disconected from the server.", player.Alias()), int(lobby.ID))

	lobby.AfterPlayerNotInGameFunc(player, 5*time.Minute, func() {
		lobby.Substitute(player)
		player.NewReport(playerpackage.Substitute, lobby.ID)
		chat.SendNotification(fmt.Sprintf("%s has been reported for not joining the game in 5 minutes", player.Alias()), int(lobby.ID))
	})
}
示例#2
0
文件: lobby.go 项目: TF2Stadium/Helen
func (Lobby) LobbyClose(so *wsevent.Client, args struct {
	Id *uint `json:"id"`
}) interface{} {

	player := chelpers.GetPlayer(so.Token)
	lob, tperr := lobby.GetLobbyByIDServer(uint(*args.Id))
	if tperr != nil {
		return tperr
	}

	if player.SteamID != lob.CreatedBySteamID && !(player.Role == helpers.RoleAdmin || player.Role == helpers.RoleMod) {
		return errors.New("Player not authorized to close lobby.")

	}

	if lob.State == lobby.Ended {
		return errors.New("Lobby already closed.")
	}

	lob.Close(true, false)

	notify := fmt.Sprintf("Lobby closed by %s", player.Alias())
	chat.SendNotification(notify, int(lob.ID))

	return emptySuccess
}
示例#3
0
文件: event.go 项目: TF2Stadium/Helen
func playerConn(steamID string, lobbyID uint) {
	player, _ := playerpackage.GetPlayerBySteamID(steamID)
	lobby, _ := lobbypackage.GetLobbyByID(lobbyID)

	lobby.SetInGame(player)
	chat.SendNotification(fmt.Sprintf("%s has connected to the server.", player.Alias()), int(lobby.ID))
}
示例#4
0
文件: event.go 项目: TF2Stadium/Helen
func disconnectedFromServer(lobbyID uint) {
	lobby, err := lobbypackage.GetLobbyByIDServer(lobbyID)
	if err != nil {
		logrus.Error("Couldn't find lobby ", lobbyID, " in database")
		return
	}

	lobby.Close(false, false)
	chat.SendNotification("Lobby Closed (Connection to server lost)", int(lobby.ID))
}
示例#5
0
文件: lobby.go 项目: TF2Stadium/Helen
func (lobby *Lobby) DownloadDemo(context *servemetf.Context) {
	file := fmt.Sprintf("%s/%d.dem", config.Constants.DemosFolder,
		lobby.ID)
	err := context.DownloadDemo(lobby.ServemeID, lobby.CreatedBySteamID, file)
	if err != nil {
		logrus.Error(err)
	} else {
		url := fmt.Sprintf("%s/demos/%d.dem", config.Constants.PublicAddress, lobby.ID)
		chat.SendNotification("STV Demo for this lobby is available at "+url, int(lobby.ID))
	}
}
示例#6
0
文件: main.go 项目: TF2Stadium/Helen
func shutdown() {
	logrus.Info("Received SIGINT/SIGTERM")
	chat.SendNotification(`Backend will be going down for a while for an update, click on "Reconnect" to reconnect to TF2Stadium`, 0)
	logrus.Info("waiting for GlobalWait")
	helpers.GlobalWait.Wait()
	logrus.Info("waiting for socket requests to complete.")
	socketServer.Wait()
	logrus.Info("closing all active websocket connections")
	socketServer.AuthServer.Close()
	logrus.Info("stopping event listener")
	event.StopListening()
}
示例#7
0
文件: lobby.go 项目: TF2Stadium/Helen
//Substitute sets the needs_sub column of the given slot to true, and broadcasts the new
//substitute list
func (lobby *Lobby) Substitute(player *player.Player) {
	lobby.Lock()
	db.DB.Model(&LobbySlot{}).Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).UpdateColumn("needs_sub", true)
	lobby.Unlock()

	var count int
	db.DB.Model(&LobbySlot{}).Where("lobby_id = ? AND needs_sub = TRUE", lobby.ID).Count(&count)
	if count == maxSubs[lobby.Type] {
		chat.SendNotification("Lobby closed (Too many subs).", int(lobby.ID))
		lobby.Close(true, false)
	}

	db.DB.Preload("Stats").First(player, player.ID)
	player.Stats.IncreaseSubCount()
	BroadcastSubList()
}
示例#8
0
文件: lobby.go 项目: TF2Stadium/Helen
//ServemeCheck checks the status of the serveme reservation for the lobby
//(if any) every 10 seconds in a goroutine, and closes the lobby if it has ended
func (l *Lobby) ServemeCheck(context *servemetf.Context) {
	go func() {
		for {
			ended, err := context.Ended(l.ServemeID, l.CreatedBySteamID)
			if err != nil {
				logrus.Error(err)
			}
			if ended {
				if l.CurrentState() != Ended {
					chat.SendNotification("Lobby Closed (Serveme reservation ended.)", int(l.ID))
					l.Close(true, false)
				}
				return
			}
			time.Sleep(10 * time.Second)
		}
	}()
}
示例#9
0
文件: event.go 项目: TF2Stadium/Helen
func playerSub(steamID string, lobbyID uint, self bool) {
	player, _ := playerpackage.GetPlayerBySteamID(steamID)
	lobby, err := lobbypackage.GetLobbyByID(lobbyID)
	if err != nil {
		logrus.Error(err)
		return
	}

	lobby.Substitute(player)
	if self {
		player.NewReport(playerpackage.Substitute, lobby.ID)

	} else {
		// ban player from joining lobbies for 30 minutes
		player.NewReport(playerpackage.Vote, lobby.ID)
	}

	chat.SendNotification(fmt.Sprintf("%s has been reported.", player.Alias()), int(lobby.ID))
}
示例#10
0
文件: event.go 项目: TF2Stadium/Helen
func matchEnded(lobbyID uint, logsID int) {
	lobby, err := lobbypackage.GetLobbyByIDServer(lobbyID)
	if err != nil {
		logrus.Error(err)
		return
	}
	lobby.Close(false, true)

	logs := fmt.Sprintf("http://logs.tf/%d", logsID)
	msg := fmt.Sprintf("Lobby Ended. Logs: %s", logs)
	chat.SendNotification(msg, int(lobby.ID))

	room := fmt.Sprintf("%d_private", lobby.ID)
	broadcaster.SendMessageToRoom(room, "lobbyLogs", struct {
		LobbyID uint   `json:"lobbyID"`
		Logs    string `json:"logs"`
	}{lobby.ID, logs})

	lobby.UpdateHours(logsID)
}
示例#11
0
文件: lobby.go 项目: TF2Stadium/Helen
func AfterLobbyJoin(so *wsevent.Client, lob *lobby.Lobby, player *player.Player) {
	room := fmt.Sprintf("%s_private", GetLobbyRoom(lob.ID))
	//make all sockets join the private room, given the one the player joined the lobby on
	//might close, so lobbyStart and lobbyReadyUp can be sent to other tabs
	sockets, _ := sessions.GetSockets(player.SteamID)
	for _, so := range sockets {
		socket.AuthServer.Join(so, room)
	}
	if lob.State == lobby.InProgress { // player is a substitute
		lob.AfterPlayerNotInGameFunc(player, 5*time.Minute, func() {
			// if player doesn't join game server in 5 minutes,
			// substitute them
			message := player.Alias() + " has been reported for not joining the game within 5 minutes"
			chat.SendNotification(message, int(lob.ID))
			lob.Substitute(player)
		})
	}

	broadcaster.SendMessage(player.SteamID, "lobbyJoined", lobby.DecorateLobbyData(lob, false))
}
示例#12
0
文件: event.go 项目: TF2Stadium/Helen
func reservationEnded(lobbyID uint) {
	lobby, _ := lobbypackage.GetLobbyByID(lobbyID)
	lobby.Close(false, false)
	chat.SendNotification("Lobby Closed (serveme.tf reservation ended)", int(lobby.ID))
}