Example #1
0
func AfterLobbyJoin(server *wsevent.Server, so *wsevent.Client, lobby *models.Lobby, player *models.Player) {
	room := fmt.Sprintf("%s_private", GetLobbyRoom(lobby.ID))
	server.AddClient(so, room)

	bytes, _ := json.Marshal(models.DecorateLobbyData(lobby, false))
	broadcaster.SendMessage(player.SteamId, "lobbyJoined", string(bytes))
}
Example #2
0
func AfterLobbyJoin(so *wsevent.Client, lobby *models.Lobby, player *models.Player) {
	room := fmt.Sprintf("%s_private", GetLobbyRoom(lobby.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.AddClient(so, room)
	}

	broadcaster.SendMessage(player.SteamID, "lobbyJoined", models.DecorateLobbyData(lobby, false))
}
Example #3
0
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

}
Example #4
0
func ServerInit(server *wsevent.Server, noAuthServer *wsevent.Server) {
	server.OnDisconnect = onDisconnect
	server.Extractor = getEvent

	noAuthServer.OnDisconnect = onDisconnect
	noAuthServer.Extractor = getEvent

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

		if reqerr != nil {
			bytes, _ := json.Marshal(reqerr)
			return bytes
		}

		bytes, _ := json.Marshal(struct {
			Message string `json:"message"`
		}{"authenticated"})
		return bytes
	})
	//Global Handlers
	server.Register(handler.Global{})
	//Lobby Handlers
	server.Register(handler.Lobby{})
	//server.On("lobbyCreate", handler.LobbyCreate)
	//Player Handlers
	server.Register(handler.Player{})
	//Chat Handlers
	server.Register(handler.Chat{})
	//Admin Handlers
	server.Register(handler.Admin{})
	//Debugging handlers
	// if config.Constants.ServerMockUp {
	// 	server.On("debugLobbyFill", handler.DebugLobbyFill)
	// 	server.On("debugLobbyReady", handler.DebugLobbyReady)
	// 	server.On("debugUpdateStatsFilter", handler.DebugUpdateStatsFilter)
	// 	server.On("debugPlayerSub", handler.DebugPlayerSub)
	// }

	noAuthServer.On("lobbySpectatorJoin", func(s *wsevent.Server, so *wsevent.Client, data []byte) []byte {
		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()
		}

		chelpers.AfterLobbySpec(s, so, lob)
		bytes, _ := json.Marshal(models.DecorateLobbyData(lob, true))

		so.EmitJSON(helpers.NewRequest("lobbyData", string(bytes)))

		return chelpers.EmptySuccessJS
	})
	noAuthServer.On("getSocketInfo", (handler.Global{}).GetSocketInfo)

	noAuthServer.DefaultHandler = func(_ *wsevent.Server, so *wsevent.Client, data []byte) []byte {
		return helpers.NewTPError("Player isn't logged in.", -4).Encode()
	}
}