当前位置: 首页>>代码示例>>Golang>>正文


Golang wsevent.Client类代码示例

本文整理汇总了Golang中github.com/TF2Stadium/wsevent.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PlayerSettingsSet

func (Player) PlayerSettingsSet(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	reqerr := chelpers.FilterRequest(so, 0, true)

	if reqerr != nil {
		return reqerr.Encode()
	}
	var args struct {
		Key   string `json:"key"`
		Value string `json:"value"`
	}

	err := chelpers.GetParams(data, &args)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))

	err = player.SetSetting(args.Key, args.Value)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:25,代码来源:player.go

示例2: LobbyLeave

func (Lobby) LobbyLeave(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"`
	}
	if err := chelpers.GetParams(data, &args); err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	steamId := chelpers.GetSteamId(so.Id())

	lob, player, tperr := removePlayerFromLobby(*args.Id, steamId)
	if tperr != nil {
		return tperr.Encode()
	}

	chelpers.AfterLobbyLeave(server, so, lob, player)

	return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:25,代码来源:lobby.go

示例3: PlayerSettingsSet

func (Player) PlayerSettingsSet(so *wsevent.Client, args struct {
	Key   *string `json:"key"`
	Value *string `json:"value"`
}) interface{} {

	player, _ := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID))

	err := player.SetSetting(*args.Key, *args.Value)
	if err != nil {
		return helpers.NewTPErrorFromError(err)
	}

	switch *args.Key {
	case "siteAlias":
		profile := models.DecoratePlayerProfileJson(player)
		so.EmitJSON(helpers.NewRequest("playerProfile", profile))

		if lobbyID, _ := player.GetLobbyID(true); lobbyID != 0 {
			lobby, _ := models.GetLobbyByID(lobbyID)
			lobbyData := lobby.LobbyData(true)
			lobbyData.Send()
		}
	case "mumbleNick":
		if !reMumbleNick.MatchString(*args.Value) {
			return helpers.NewTPError("Invalid Mumble nick.", -1)
		}
	}

	return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:30,代码来源:player.go

示例4: PlayerSettingsGet

func (Player) PlayerSettingsGet(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	reqerr := chelpers.FilterRequest(so, 0, true)

	if reqerr != nil {
		return reqerr.Encode()
	}
	var args struct {
		Key string `json:"key"`
	}

	err := chelpers.GetParams(data, &args)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))

	var settings []models.PlayerSetting
	var setting models.PlayerSetting
	if args.Key == "*" {
		settings, err = player.GetSettings()
	} else {
		setting, err = player.GetSetting(args.Key)
		settings = append(settings, setting)
	}

	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	result := models.DecoratePlayerSettingsJson(settings)
	resp, _ := chelpers.BuildSuccessJSON(result).Encode()
	return resp
}
开发者ID:demipixel,项目名称:Helen,代码行数:34,代码来源:player.go

示例5: PlayerProfile

func (Player) PlayerProfile(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	reqerr := chelpers.FilterRequest(so, 0, true)

	if reqerr != nil {
		return reqerr.Encode()
	}
	var args struct {
		Steamid string `json:"steamid"`
	}

	err := chelpers.GetParams(data, &args)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	steamid := args.Steamid
	if steamid == "" {
		steamid = chelpers.GetSteamId(so.Id())
	}

	player, playErr := models.GetPlayerWithStats(steamid)

	if playErr != nil {
		return playErr.Encode()
	}

	result := models.DecoratePlayerProfileJson(player)
	resp, _ := chelpers.BuildSuccessJSON(result).Encode()
	return resp
}
开发者ID:demipixel,项目名称:Helen,代码行数:30,代码来源:player.go

示例6: RequestLobbyListData

func (Lobby) RequestLobbyListData(so *wsevent.Client, _ struct{}) interface{} {
	var lobbies []models.Lobby
	db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies)
	so.EmitJSON(helpers.NewRequest("lobbyListData", models.DecorateLobbyListData(lobbies)))

	return chelpers.EmptySuccessJS
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:7,代码来源:lobby.go

示例7: PlayerSettingsSet

func (Player) PlayerSettingsSet(so *wsevent.Client, args struct {
	Key   *string `json:"key"`
	Value *string `json:"value"`
}) interface{} {

	player := chelpers.GetPlayer(so.Token)

	switch *args.Key {
	case "siteAlias":
		if len(*args.Value) > 32 {
			return errors.New("Site alias must be under 32 characters long.")
		}

		player.SetSetting(*args.Key, *args.Value)

		player.SetPlayerProfile()
		so.EmitJSON(helpers.NewRequest("playerProfile", player))

		if lobbyID, _ := player.GetLobbyID(true); lobbyID != 0 {
			lob, _ := lobby.GetLobbyByID(lobbyID)
			slot, _ := lob.GetPlayerSlot(player)
			player.SetMumbleUsername(lob.Type, slot)
			lobby.BroadcastLobby(lob)
		}
	default:
		player.SetSetting(*args.Key, *args.Value)
	}

	return emptySuccess
}
开发者ID:TF2Stadium,项目名称:Helen,代码行数:30,代码来源:player.go

示例8: 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
}
开发者ID:demipixel,项目名称:Helen,代码行数:60,代码来源:lobby.go

示例9: RequestLobbyListData

func (Lobby) RequestLobbyListData(_ *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	var lobbies []models.Lobby
	db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies)
	list, _ := json.Marshal(models.DecorateLobbyListData(lobbies))
	so.EmitJSON(helpers.NewRequest("lobbyListData", string(list)))

	return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:8,代码来源:lobby.go

示例10: BroadcastScrollback

func BroadcastScrollback(so *wsevent.Client, room uint) {
	messages, err := chat.GetScrollback(int(room))
	if err != nil {
		return
	}

	so.EmitJSON(helpers.NewRequest("chatScrollback", messages))
}
开发者ID:TF2Stadium,项目名称:Helen,代码行数:8,代码来源:chatScrollback.go

示例11: GetSocketInfo

func (Global) GetSocketInfo(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	socketinfo := struct {
		ID    string   `json:"id"`
		Rooms []string `json:"rooms"`
	}{so.Id(), server.RoomsJoined(so.Id())}

	bytes, _ := json.Marshal(socketinfo)
	return bytes
}
开发者ID:demipixel,项目名称:Helen,代码行数:9,代码来源:global.go

示例12: 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
}
开发者ID:demipixel,项目名称:Helen,代码行数:56,代码来源:chat.go

示例13: FilterRequest

func FilterRequest(so *wsevent.Client, action authority.AuthAction, login bool) (err *helpers.TPError) {
	if int(action) != 0 {
		var role, _ = GetPlayerRole(so.Id())
		can := role.Can(action)
		if !can {
			err = helpers.NewTPError("You are not authorized to perform this action.", 0)
		}
	}
	return
}
开发者ID:demipixel,项目名称:Helen,代码行数:10,代码来源:filters.go

示例14: 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)))
}
开发者ID:demipixel,项目名称:Helen,代码行数:11,代码来源:playerHelpers.go

示例15: BroadcastScrollback

func BroadcastScrollback(so *wsevent.Client, room uint) {
	// bytes, _ := json.Marshal(ChatHistoryClearEvent{room})
	// so.EmitJSON(helpers.NewRequest("chatHistoryClear", string(bytes)))

	messages, err := models.GetScrollback(int(room))
	if err != nil {
		return
	}

	for i := len(messages) - 1; i != -1; i-- {
		so.EmitJSON(helpers.NewRequest("chatReceive", messages[i]))
	}
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:13,代码来源:chatScrollback.go


注:本文中的github.com/TF2Stadium/wsevent.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。