void OnClientBeginAuthentication(CSteamID clientID, byte[] pToken, int uTokenLen) { // If the clientdata is already in use, refuse anymore connections if (ClientData.bActive) { // CallbackMsg_t msg; // Tell the client that authentication failed or server is full // BSendDataToClient(clientID, &msg, sizeof(msg)); MsgServerFailAuthentication msg = new MsgServerFailAuthentication(); byte[] msg_array = Converter.ObjectToByteArray(msg); uint size = (uint)(msg_array.Length * sizeof(byte)); // Another way to calculate size, dont know if it works SteamGameServerNetworking.SendP2PPacket(clientID, msg_array, (uint)Marshal.SizeOf(msg_array), EP2PSend.k_EP2PSendReliable); return; } else { // ClientData[i].TickCountSinceLastData = Current Game Tick Time // Authenticate User With Steam Back-End Servers if (SteamGameServer.BeginAuthSession(pToken, uTokenLen, clientID) != EBeginAuthSessionResult.k_EBeginAuthSessionResultOK) { MsgServerFailAuthentication msg = new MsgServerFailAuthentication(); byte[] msg_array = Converter.ObjectToByteArray(msg); uint size = (uint)(msg_array.Length * sizeof(byte)); // Another way to calculate size, dont know if it works SteamGameServerNetworking.SendP2PPacket(clientID, msg_array, (uint)Marshal.SizeOf(msg_array), EP2PSend.k_EP2PSendReliable); } ClientData.SteamIDUser = clientID; ClientData.bActive = true; } }
/// <summary> /// <para>Authenticate the ticket from the entity Steam ID to be sure it is valid and isn't reused.</para> /// <a href="https://partner.steamgames.com/doc/api/ISteamGameServer#BeginAuthSession">https://partner.steamgames.com/doc/api/ISteamGameServer#BeginAuthSession</a> /// </summary> /// <param name="authTicket"></param> /// <param name="user"></param> /// <param name="callback"></param> public static void ServerBeginAuthSession(byte[] authTicket, CSteamID user, Action <Session> callback) { RegisterCallbacks(); var session = new Session() { isClientSession = false, User = user, OnStartCallback = callback }; if (ActiveSessions == null) { ActiveSessions = new List <Session>(); } ActiveSessions.Add(session); SteamGameServer.BeginAuthSession(authTicket, authTicket.Length, user); }
/// <summary> /// Checks if the given <see cref="NetIncomingMessageType.ConnectionApproval" /> request is authorized. /// </summary> /// <param name="msg"></param> private void AuthorizeConnection(NetIncomingMessage msg) { var authTicket = msg.ReadBytes(1024); var pcbTicket = msg.ReadUInt32(); var steamId = new CSteamID(msg.ReadUInt64()); var result = SteamGameServer.BeginAuthSession(authTicket, (int)pcbTicket, steamId); var connection = msg.SenderConnection; if (result == EBeginAuthSessionResult.k_EBeginAuthSessionResultOK) { connection.Approve(); Logger.Info($"Connection {connection.RemoteEndPoint} approved."); } else { connection.Deny(result.ToString()); Logger.Warn($"Connection {connection.RemoteEndPoint} was not approved: {result}"); } }
public override bool VerifyTicket(Identity ident, byte[] data) { return(SteamGameServer.BeginAuthSession(data, data.Length, (CSteamID)(SteamIdentity)ident) == EBeginAuthSessionResult.k_EBeginAuthSessionResultOK); }