Exemple #1
0
//SocketInit initializes the websocket connection for the provided socket
func SocketInit(so *wsevent.Client) error {
	chelpers.AuthenticateSocket(so.ID, so.Request)
	loggedIn := chelpers.IsLoggedInSocket(so.ID)
	if loggedIn {
		steamid := chelpers.GetSteamId(so.ID)
		sessions.AddSocket(steamid, so)
	}

	if loggedIn {
		hooks.AfterConnect(socket.AuthServer, so)

		player, err := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID))
		if err != nil {
			logrus.Warning(
				"User has a cookie with but a matching player record doesn't exist: %s",
				chelpers.GetSteamId(so.ID))
			chelpers.DeauthenticateSocket(so.ID)
			hooks.AfterConnect(socket.UnauthServer, so)
			return ErrRecordNotFound
		}

		hooks.AfterConnectLoggedIn(so, player)
	} else {
		hooks.AfterConnect(socket.UnauthServer, so)
		so.EmitJSON(helpers.NewRequest("playerSettings", "{}"))
		so.EmitJSON(helpers.NewRequest("playerProfile", "{}"))
	}

	so.EmitJSON(helpers.NewRequest("socketInitialized", "{}"))

	return nil
}
Exemple #2
0
//SocketInit initializes the websocket connection for the provided socket
func SocketInit(so *wsevent.Client) error {
	loggedIn := so.Token != nil

	if loggedIn {
		hooks.AfterConnect(socket.AuthServer, so)

		steamid := so.Token.Claims.(*chelpers.TF2StadiumClaims).SteamID

		player, err := player.GetPlayerBySteamID(steamid)
		if err != nil {
			return fmt.Errorf("Couldn't find player record for %s", steamid)
		}

		hooks.AfterConnectLoggedIn(so, player)
	} else {
		hooks.AfterConnect(socket.UnauthServer, so)
		so.EmitJSON(helpers.NewRequest("playerSettings", "{}"))
		so.EmitJSON(helpers.NewRequest("playerProfile", "{}"))
	}

	so.EmitJSON(helpers.NewRequest("socketInitialized", "{}"))

	return nil
}