Esempio n. 1
0
        /// <summary>
        /// Callback for when a connection had disconnected
        /// </summary>
        /// <param name="client">The client object whom is disconnecting</param>
        private void ClientDisconnected(GPCMClient client)
        {
            // If we are exiting, don't do anything here.
            if (Exiting)
            {
                return;
            }

            // Remove client, and call OnUpdate Event
            try
            {
                // Remove client from online list
                if (Clients.TryRemove(client.PlayerInfo.PlayerId, out client) && !client.Disposed)
                {
                    client.DisconnectByReason(DisconnectReason.NormalLogout);
                }

                // Add player to database queue
                PlayerStatusQueue.Enqueue(client);
            }
            catch (Exception e)
            {
                LogWriter.Log.Write(LogLevel.Error, "An Error occured at [GPCMClient._OnDisconnect] : Generating Exception Log {0}", e.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks the timeout on a client connection. This method is used to detect hanging connections, and
        /// forcefully disconnects them.
        /// </summary>
        /// <param name="client"></param>
        protected void CheckTimeout(GPCMClient client)
        {
            // Setup vars
            DateTime   expireTime = client.Created.AddSeconds(Timeout);
            GPCMClient oldC;

            // Remove all processing connections that are hanging
            if (client.PlayerInfo.LoginStatus != LoginStatus.Completed && expireTime <= DateTime.Now)
            {
                try
                {
                    client.DisconnectByReason(DisconnectReason.LoginTimedOut);
                    Processing.TryRemove(client.ConnectionID, out oldC);
                }
                catch (Exception e)
                {
                    LogWriter.Log.WriteException(e);
                }
            }
            //else if (client.Status == LoginStatus.Completed)
            //{
            //Processing.TryRemove(client.ConnectionId, out oldC);
            //}
        }
Esempio n. 3
0
        public static void Switch(GPCMClient client, Dictionary <string, string> recv, GPCMConnectionUpdate OnSuccessfulLogin, GPCMStatusChanged OnStatusChanged)
        {
            string command = recv.Keys.First();

            try
            {
                switch (command)
                {
                case "inviteto":
                    InviteToHandler.AddFriends(client, recv);
                    break;

                case "login":
                    LoginHandler.ProcessLogin(client, recv, OnSuccessfulLogin, OnStatusChanged);
                    break;

                case "getprofile":
                    GetProfileHandler.SendProfile(client, recv);
                    break;

                case "addbuddy":
                    AddBuddyHandler.Addfriends(client, recv);
                    break;

                case "delbuddy":
                    DelBuddyHandler.Handle(client, recv);
                    break;

                case "updateui":
                    UpdateUiHandler.UpdateUi(client, recv);
                    break;

                case "updatepro":
                    UpdateProHandler.UpdateUser(client, recv);
                    break;

                case "registernick":
                    RegisterNickHandler.RegisterNick(client, recv);
                    break;

                case "logout":
                    client.DisconnectByReason(DisconnectReason.NormalLogout);
                    break;

                case "status":
                    StatusHandler.UpdateStatus(client, recv, OnStatusChanged);
                    break;

                case "newuser":
                    NewUserHandler.NewUser(client, recv);
                    break;

                case "ka":
                    KAHandler.SendKeepAlive(client);
                    break;

                default:
                    LogWriter.Log.Write("[GPCM] received unknown data " + command, LogLevel.Debug);
                    GameSpyUtils.SendGPError(client, GPErrorCode.General, "An invalid request was sended.");
                    break;
                }
            }
            catch (Exception e)
            {
                LogWriter.Log.WriteException(e);
            }
        }