示例#1
0
        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;
            }
        }
示例#2
0
        void OnAuthCompleted(bool bAuthSeuccessful)
        {
            if (!ClientData.bActive)
            {
                Console.WriteLine("Goth authentication completed callback for non-active slot");
                return;
            }

            if (!bAuthSeuccessful)
            {
                // Tell GS that user is leaving
                SteamGameServer.EndAuthSession(ClientData.SteamIDUser);

                // Send out deny to client
                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(ClientData.SteamIDUser, msg_array, (uint)Marshal.SizeOf(msg_array), EP2PSend.k_EP2PSendReliable);

                // Clear out client data
                ClientData.bActive = false;
                return;
            }

            // The client has passes authentication, integrate it into game
            // For example setting up name and score and maybe even level
            // Also tell them they've joined
            MsgServerPassAuthentication pass_msg = new MsgServerPassAuthentication();

            byte[] pass_array = Converter.ObjectToByteArray(pass_msg);

            SteamGameServerNetworking.SendP2PPacket(ClientData.SteamIDUser, pass_array, (uint)Marshal.SizeOf(pass_array), EP2PSend.k_EP2PSendReliable);



            // Check if there are two players, if there are we just need them to be reeady
            // and then the game will start. players will have a button to allow them to
            // denote if they are ready or not. need to add server states and change lobby
            // states to be able to accept server incoming messages
            // Basically Start the Game
        }