• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang wsevent.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: AfterConnect

func AfterConnect(server *wsevent.Server, so *wsevent.Client) {
	server.AddClient(so, fmt.Sprintf("%s_public", config.GlobalChatRoom)) //room for global chat

	var lobbies []models.Lobby
	err := db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies).Error
	if err != nil {
		logrus.Error(err)
		return
	}

	so.EmitJSON(helpers.NewRequest("lobbyListData", models.DecorateLobbyListData(lobbies)))
	chelpers.BroadcastScrollback(so, 0)
	so.EmitJSON(helpers.NewRequest("subListData", models.DecorateSubstituteList()))
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:14,代码来源:player.go


示例17: SocketHandler

func SocketHandler(w http.ResponseWriter, r *http.Request) {
	//check if player is in the whitelist
	if config.Constants.SteamIDWhitelist != "" {
		allowed := false

		session, err := chelpers.GetSessionHTTP(r)
		if err == nil {
			steamid, ok := session.Values["steam_id"]
			allowed = ok && chelpers.IsSteamIDWhitelisted(steamid.(string))
		}
		if !allowed {
			http.Error(w, "Sorry, but you're not in the closed alpha", 403)
			return
		}
	}

	session, err := chelpers.GetSessionHTTP(r)
	var so *wsevent.Client

	if err == nil {
		_, ok := session.Values["steam_id"]
		if ok {
			so, err = socket.AuthServer.NewClient(upgrader, w, r)
		} else {
			so, err = socket.UnauthServer.NewClient(upgrader, w, r)
		}
		pprof.Clients.Add(1)

	} else {
		var estr = "Couldn't create WebSocket connection."
		//estr = err.Error()

		logrus.Error(err.Error())
		http.Error(w, estr, 500)
		return
	}

	if err != nil || so == nil {
		login.LogoutSession(w, r)
		return
	}

	//logrus.Debug("Connected to Socket")
	err = SocketInit(so)
	if err != nil {
		login.LogoutSession(w, r)
		so.Close()
	}
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:49,代码来源:websocket.go


示例18: LobbySpectatorJoin

func (Unauth) LobbySpectatorJoin(so *wsevent.Client, args struct {
	ID *uint `json:"id"`
}) interface{} {

	lob, err := lobby.GetLobbyByID(*args.ID)

	if err != nil {
		return err
	}

	hooks.AfterLobbySpec(socket.UnauthServer, so, nil, lob)

	so.EmitJSON(helpers.NewRequest("lobbyData", lobby.DecorateLobbyData(lob, true)))

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


示例19: UnAuthSpecJoin

func (Lobby) UnAuthSpecJoin(so *wsevent.Client, args struct {
	ID *uint `json:"id"`
}) interface{} {

	var lob *models.Lobby
	lob, tperr := models.GetLobbyByID(*args.ID)

	if tperr != nil {
		return tperr
	}

	hooks.AfterLobbySpec(socket.UnauthServer, so, lob)

	so.EmitJSON(helpers.NewRequest("lobbyData", models.DecorateLobbyData(lob, true)))

	return chelpers.EmptySuccessJS

}
开发者ID:gpittarelli,项目名称:Helen,代码行数:18,代码来源:server.go


示例20: SocketHandler

func SocketHandler(w http.ResponseWriter, r *http.Request) {
	token, err := chelpers.GetToken(r)
	if err != nil && err != http.ErrNoCookie { //invalid jwt token
		logrus.Errorf("Error reading JWT: %v", err)
		token = nil
	}

	//check if player is in the whitelist
	if config.Constants.SteamIDWhitelist != "" {
		if token == nil {
			// player isn't logged in,
			// and access is restricted to logged in people
			http.Error(w, "Not logged in", http.StatusForbidden)
			return
		}

		if !chelpers.IsSteamIDWhitelisted(token.Claims.(*chelpers.TF2StadiumClaims).SteamID) {
			http.Error(w, "you're not in the beta", http.StatusForbidden)
			return
		}
	}

	var so *wsevent.Client

	if token != nil { //received valid jwt
		so, err = socket.AuthServer.NewClient(upgrader, w, r)
	} else {
		so, err = socket.UnauthServer.NewClient(upgrader, w, r)
	}

	if err != nil {
		return
	}

	so.Token = token

	//logrus.Debug("Connected to Socket")
	err = SocketInit(so)
	if err != nil {
		logrus.Error(err)
		so.Close()
		return
	}
}
开发者ID:TF2Stadium,项目名称:Helen,代码行数:44,代码来源:websocket.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang wsevent.Server类代码示例发布时间:2022-05-28
下一篇:
Golang testhelpers.CleanupDB函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap