本文整理汇总了Golang中github.com/TF2Stadium/Helen/controllers/broadcaster.SendMessageToRoom函数的典型用法代码示例。如果您正苦于以下问题:Golang SendMessageToRoom函数的具体用法?Golang SendMessageToRoom怎么用?Golang SendMessageToRoom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SendMessageToRoom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BroadcastLobby
func BroadcastLobby(lobby *Lobby) {
bytes, _ := DecorateLobbyDataJSON(lobby, true).Encode()
room := strconv.FormatUint(uint64(lobby.ID), 10)
broadcaster.SendMessageToRoom(room, "lobbyData", string(bytes))
broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public", room), "lobbyData", string(bytes))
}
示例2: BroadcastLobby
func BroadcastLobby(lobby *Lobby) {
//db.DB.Preload("Spectators").First(&lobby, lobby.ID)
bytes, _ := json.Marshal(DecorateLobbyData(lobby, true))
room := strconv.FormatUint(uint64(lobby.ID), 10)
broadcaster.SendMessageToRoom(room, "lobbyData", string(bytes))
broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public", room), "lobbyData", string(bytes))
}
示例3: BroadcastLobbyList
//BroadcastLobbyList broadcasts the lobby list to all users
func BroadcastLobbyList() {
lobbies := []Lobby{}
db.DB.Where("state = ?", LobbyStateWaiting).Order("id desc").Find(&lobbies)
broadcaster.SendMessageToRoom(
fmt.Sprintf("%s_public", config.GlobalChatRoom),
"lobbyListData", DecorateLobbyListData(lobbies))
}
示例4: DebugLobbyFill
func DebugLobbyFill(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, debugLobbyFillFilter,
func(param map[string]interface{}) string {
id := param["id"].(uint)
lobby, _ := models.GetLobbyById(id)
var players []*models.Player
for i := 1; i < int(lobby.Type)*2; i++ {
steamid := "DEBUG" + strconv.FormatUint(uint64(time.Now().Unix()), 10) + strconv.Itoa(i)
player, _ := models.NewPlayer(steamid)
player.Debug = true
player.Save()
players = append(players, player)
lobby.AddPlayer(player, i)
}
lobby.State = models.LobbyStateReadyingUp
lobby.Save()
room := fmt.Sprintf("%s_public", chelpers.GetLobbyRoom(lobby.ID))
broadcaster.SendMessageToRoom(room, "lobbyReadyUp", "")
lobby.ReadyUpTimeoutCheck()
bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例5: BroadcastLobbyList
func BroadcastLobbyList() {
var lobbies []Lobby
db.DB.Where("state = ?", LobbyStateWaiting).Order("id desc").Find(&lobbies)
bytes, _ := json.Marshal(DecorateLobbyListData(lobbies))
broadcaster.SendMessageToRoom(
fmt.Sprintf("%s_public", config.Constants.GlobalChatRoom),
"lobbyListData", string(bytes))
}
示例6: Close
//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()
}
示例7: ChatSend
func (Chat) ChatSend(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, 0, true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Message *string `json:"message"`
Room *int `json:"room"`
}
err := chelpers.GetParams(data, &args)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
return tperr.Encode()
}
//helpers.Logger.Debug("received chat message: %s %s", *args.Message, player.Name)
if *args.Room > 0 {
spec := player.IsSpectatingId(uint(*args.Room))
//Check if player has either joined, or is spectating lobby
lobbyId, tperr := player.GetLobbyId()
if tperr != nil && !spec && lobbyId != uint(*args.Room) {
return helpers.NewTPError("Player is not in the lobby.", 5).Encode()
}
} else {
// else room is the lobby list room
*args.Room, _ = strconv.Atoi(config.Constants.GlobalChatRoom)
}
if (*args.Message)[0] == '\n' {
return helpers.NewTPError("Cannot send messages prefixed with newline", 4).Encode()
}
if len(*args.Message) > 120 {
return helpers.NewTPError("Message too long", 4).Encode()
}
message := models.NewChatMessage(*args.Message, *args.Room, player)
db.DB.Save(message)
bytes, _ := json.Marshal(message)
broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public",
chelpers.GetLobbyRoom(uint(*args.Room))),
"chatReceive", string(bytes))
if strings.HasPrefix(*args.Message, "!admin") {
chelpers.SendToSlack(*args.Message, player.Name, player.SteamId)
}
return chelpers.EmptySuccessJS
}
示例8: BroadcastLobbyList
func BroadcastLobbyList() {
var lobbies []Lobby
db.DB.Where("state = ?", LobbyStateWaiting).Order("id desc").Find(&lobbies)
list, err := DecorateLobbyListData(lobbies)
if err != nil {
helpers.Logger.Warning("Failed to send lobby list: %s", err.Error())
} else {
broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public", config.Constants.GlobalChatRoom), "lobbyListData", list)
}
}
示例9: Close
func (lobby *Lobby) Close(rpc bool) {
db.DB.Table("substitutes").Where("lobby_id = ?", lobby.ID).UpdateColumn("filled", true)
db.DB.First(&lobby).UpdateColumn("state", LobbyStateEnded)
db.DB.Delete(&lobby.ServerInfo)
db.DB.Exec("DELETE FROM spectators_players_lobbies WHERE lobby_id = ?", lobby.ID)
if rpc {
End(lobby.ID)
}
privateRoom := fmt.Sprintf("%d_private", lobby.ID)
bytesLobbyLeft, _ := json.Marshal(DecorateLobbyLeave(lobby))
broadcaster.SendMessageToRoom(privateRoom, "lobbyLeft", string(bytesLobbyLeft))
publicRoom := fmt.Sprintf("%d_public", lobby.ID)
bytesLobbyClosed, _ := json.Marshal(DecorateLobbyClosed(lobby))
broadcaster.SendMessageToRoom(publicRoom, "lobbyClosed", string(bytesLobbyClosed))
BroadcastLobby(lobby)
}
示例10: Close
//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(rpc bool) {
db.DB.First(&lobby).UpdateColumn("state", LobbyStateEnded)
db.DB.Table("server_records").Where("id = ?", lobby.ServerInfoID).Delete(&ServerRecord{})
db.DB.Table("requirements").Where("lobby_id = ?", lobby.ID).Delete(&Requirement{})
//db.DB.Exec("DELETE FROM spectators_players_lobbies WHERE lobby_id = ?", lobby.ID)
if rpc {
End(lobby.ID)
}
privateRoom := fmt.Sprintf("%d_private", lobby.ID)
broadcaster.SendMessageToRoom(privateRoom, "lobbyLeft", DecorateLobbyLeave(lobby))
publicRoom := fmt.Sprintf("%d_public", lobby.ID)
broadcaster.SendMessageToRoom(publicRoom, "lobbyClosed", DecorateLobbyClosed(lobby))
BroadcastSubList()
BroadcastLobby(lobby)
BroadcastLobbyList() // has to be done manually for now
FumbleLobbyEnded(lobby)
}
示例11: DebugRequestLobbyStart
func DebugRequestLobbyStart(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, debugRequestLobbyStartFilter,
func(params map[string]interface{}) string {
lobby, _ := models.GetLobbyById(params["id"].(uint))
bytes, _ := models.DecorateLobbyConnectJSON(lobby).Encode()
room := fmt.Sprintf("%s_private", chelpers.GetLobbyRoom(lobby.ID))
broadcaster.SendMessageToRoom(room,
"lobbyStart", string(bytes))
bytes, _ = chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例12: PlayerReady
func PlayerReady(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, playerReadyFilter,
func(_ map[string]interface{}) string {
steamid := chelpers.GetSteamId(so.Id())
player, tperr := models.GetPlayerBySteamId(steamid)
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
lobbyid, tperr := player.GetLobbyId()
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
lobby, tperr := models.GetLobbyById(lobbyid)
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
if lobby.State != models.LobbyStateReadyingUp {
bytes, _ := helpers.NewTPError("Lobby hasn't been filled up yet.", 4).ErrorJSON().Encode()
return string(bytes)
}
helpers.LockRecord(lobby.ID, lobby)
tperr = lobby.ReadyPlayer(player)
defer helpers.UnlockRecord(lobby.ID, lobby)
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
if lobby.IsEveryoneReady() {
lobby.State = models.LobbyStateInProgress
lobby.Save()
bytes, _ := models.DecorateLobbyConnectJSON(lobby).Encode()
room := fmt.Sprintf("%s_private",
chelpers.GetLobbyRoom(lobby.ID))
broadcaster.SendMessageToRoom(room,
"lobbyStart", string(bytes))
models.BroadcastLobbyList()
}
bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例13: ChatSend
func ChatSend(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, chatSendFilter,
func(params map[string]interface{}) string {
message := params["message"].(string)
room := params["room"].(int)
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
helpers.Logger.Debug("received chat message: %s %s", message, player.Name)
spec := player.IsSpectatingId(uint(room))
//Check if player has either joined, or is spectating lobby
lobbyId, tperr := player.GetLobbyId()
if room > 0 {
if tperr != nil && !spec && lobbyId != uint(room) {
bytes, _ := chelpers.BuildFailureJSON("Player is not in the lobby.", 5).Encode()
return string(bytes)
}
} else {
// else room is the lobby list room
room, _ = strconv.Atoi(config.Constants.GlobalChatRoom)
}
chatMessage := simplejson.New()
// TODO send proper timestamps
chatMessage.Set("timestamp", time.Now().Unix())
chatMessage.Set("message", message)
chatMessage.Set("room", room)
chatMessage.Set("player", models.DecoratePlayerSummaryJson(player))
bytes, _ := chatMessage.Encode()
broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public",
chelpers.GetLobbyRoom(uint(room))),
"chatReceive", string(bytes))
resp, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
chelpers.LogChat(uint(room), player.Name, player.SteamId, message)
chelpers.AddScrollbackMessage(uint(room), string(bytes))
return string(resp)
})
}
示例14: matchEnded
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)
}
示例15: LobbyShuffle
func (Lobby) LobbyShuffle(so *wsevent.Client, args struct {
Id uint `json:"id"`
}) interface{} {
player := chelpers.GetPlayer(so.Token)
lob, err := lobby.GetLobbyByID(args.Id)
if err != nil {
return err
}
if player.SteamID != lob.CreatedBySteamID && (player.Role != helpers.RoleAdmin && player.Role != helpers.RoleMod) {
return errors.New("You aren't authorized to shuffle this lobby.")
}
if err = lob.ShuffleAllSlots(); err != nil {
return err
}
room := fmt.Sprintf("%s_private", hooks.GetLobbyRoom(args.Id))
broadcaster.SendMessageToRoom(room, "lobbyShuffled", args)
chat.NewBotMessage(fmt.Sprintf("Lobby shuffled by %s", player.Alias()), int(args.Id)).Send()
return emptySuccess
}