本文整理汇总了Golang中github.com/TF2Stadium/wsevent.Server.RemoveClient方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.RemoveClient方法的具体用法?Golang Server.RemoveClient怎么用?Golang Server.RemoveClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/TF2Stadium/wsevent.Server
的用法示例。
在下文中一共展示了Server.RemoveClient方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LobbySpectatorJoin
func (Lobby) LobbySpectatorJoin(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)
if reqerr != nil {
bytes, _ := json.Marshal(reqerr)
return bytes
}
var args struct {
Id *uint `json:"id"`
}
if err := chelpers.GetParams(data, &args); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
var lob *models.Lobby
lob, tperr := models.GetLobbyById(*args.Id)
if tperr != nil {
return tperr.Encode()
}
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
return tperr.Encode()
}
var specSameLobby bool
arr, tperr := player.GetSpectatingIds()
if len(arr) != 0 {
for _, id := range arr {
if id == *args.Id {
specSameLobby = true
continue
}
lobby, _ := models.GetLobbyById(id)
lobby.RemoveSpectator(player, true)
server.RemoveClient(so.Id(), fmt.Sprintf("%d_public", id))
}
}
// If the player is already in the lobby (either joined a slot or is spectating), don't add them.
// Just Broadcast the lobby to them, so the frontend displays it.
if id, _ := player.GetLobbyId(); id != *args.Id && !specSameLobby {
tperr = lob.AddSpectator(player)
if tperr != nil {
return tperr.Encode()
}
chelpers.AfterLobbySpec(server, so, lob)
}
models.BroadcastLobbyToUser(lob, player.SteamId)
return chelpers.EmptySuccessJS
}
示例2: AfterLobbyLeave
func AfterLobbyLeave(server *wsevent.Server, so *wsevent.Client, lobby *models.Lobby, player *models.Player) {
//pub := fmt.Sprintf("%s_public", GetLobbyRoom(lobby.ID))
// bytes, _ := json.Marshal(models.DecorateLobbyData(lobby, true))
// broadcaster.SendMessageToRoom(pub, "lobbyData", string(bytes))
bytes, _ := json.Marshal(models.DecorateLobbyLeave(lobby))
broadcaster.SendMessage(player.SteamId, "lobbyLeft", string(bytes))
server.RemoveClient(so.Id(), fmt.Sprintf("%s_private", GetLobbyRoom(lobby.ID)))
}
示例3: AfterLobbySpec
func AfterLobbySpec(server *wsevent.Server, so *wsevent.Client, lobby *models.Lobby) {
//remove socket from room of the previous lobby the socket was spectating (if any)
lobbyID, ok := sessions.GetSpectating(so.ID)
if ok {
server.RemoveClient(so, fmt.Sprintf("%d_public", lobbyID))
sessions.RemoveSpectator(so.ID)
}
server.AddClient(so, fmt.Sprintf("%s_public", GetLobbyRoom(lobby.ID)))
chelpers.BroadcastScrollback(so, lobby.ID)
sessions.SetSpectator(so.ID, lobby.ID)
}
示例4: LobbyJoin
func (Lobby) LobbyJoin(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Id *uint `json:"id"`
Class *string `json:"class"`
Team *string `json:"team" valid:"red,blu"`
}
if err := chelpers.GetParams(data, &args); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
//helpers.Logger.Debug("id %d class %s team %s", *args.Id, *args.Class, *args.Team)
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
return tperr.Encode()
}
lob, tperr := models.GetLobbyById(*args.Id)
if tperr != nil {
return tperr.Encode()
}
if lob.State == models.LobbyStateEnded {
return helpers.NewTPError("Cannot join a closed lobby.", -1).Encode()
}
//Check if player is in the same lobby
var sameLobby bool
if id, err := player.GetLobbyId(); err == nil && id == *args.Id {
sameLobby = true
}
slot, tperr := models.LobbyGetPlayerSlot(lob.Type, *args.Team, *args.Class)
if tperr != nil {
return tperr.Encode()
}
if prevId, err := player.GetLobbyId(); err != nil {
server.RemoveClient(so.Id(), fmt.Sprintf("%d_public", prevId))
server.RemoveClient(so.Id(), fmt.Sprintf("%d_private", prevId))
}
tperr = lob.AddPlayer(player, slot, *args.Team, *args.Class)
if tperr != nil {
return tperr.Encode()
}
if !sameLobby {
chelpers.AfterLobbyJoin(server, so, lob, player)
}
if lob.IsFull() {
lob.State = models.LobbyStateReadyingUp
lob.ReadyUpTimestamp = time.Now().Unix() + 30
lob.Save()
tick := time.After(time.Second * 30)
id := lob.ID
stop := make(chan struct{})
go func() {
select {
case <-tick:
lobby := &models.Lobby{}
db.DB.First(lobby, id)
if lobby.State != models.LobbyStateInProgress {
err := lobby.RemoveUnreadyPlayers()
if err != nil {
helpers.Logger.Error("RemoveUnreadyPlayers: ", err.Error())
err = nil
}
err = lobby.UnreadyAllPlayers()
if err != nil {
helpers.Logger.Error("UnreadyAllPlayers: ", err.Error())
}
lobby.State = models.LobbyStateWaiting
lobby.Save()
}
case <-stop:
return
}
}()
room := fmt.Sprintf("%s_private",
chelpers.GetLobbyRoom(lob.ID))
//.........这里部分代码省略.........
示例5: AfterLobbySpecLeave
func AfterLobbySpecLeave(server *wsevent.Server, so *wsevent.Client, lobby *models.Lobby) {
server.RemoveClient(so.Id(), fmt.Sprintf("%s_public", GetLobbyRoom(lobby.ID)))
}