Beispiel #1
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="databaseDriver">
 /// A connection to a database
 /// If the databaseDriver is null, then the server will attempt to create it's own connection
 /// otherwise it will use the specified connection
 /// </param>
 public GStatsServer(string serverName, DatabaseDriver databaseDriver, IPEndPoint bindTo, int MaxConnections) : base(serverName, bindTo, MaxConnections)
 {
     //GStatsHandler.DBQuery = new GSTATSDBQuery(databaseDriver);
     DB = new DBQueryBase(databaseDriver);
     // Begin accepting connections
     StartAcceptAsync();
 }
Beispiel #2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="databaseDriver">
        /// A connection to a database
        /// If the databaseDriver is null, then the server will attempt to create it's own connection
        /// otherwise it will use the specified connection
        /// </param>
        public GPSPServer(string serverName, DatabaseDriver databaseDriver, IPEndPoint bindTo, int MaxConnections) : base(serverName, bindTo, MaxConnections)
        {
            //GPSPHandler.DBQuery = new GPSPDBQuery(databaseDriver);

            DB = new DBQueryBase(databaseDriver);

            GPSPClient.OnDisconnected += ClientDisconnected;

            // Begin accepting connections
            StartAcceptAsync();
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new instance of <see cref="GPCMClient"/>
        /// </summary>
        public GPCMServer(string serverName, DatabaseDriver driver, IPEndPoint bindTo, int maxConnections) : base(serverName, bindTo, maxConnections)
        {
            //GPCMHandler.DBQuery = new GPCMDBQuery(driver);

            DB = new DBQueryBase(driver);

            GPCMClient.OnDisconnect += ClientDisconnected;

            GPCMClient.OnSuccessfulLogin += ClientSuccessfulLogin;

            // Setup timer. Every 15 seconds should be sufficient
            if (PollTimer == null || !PollTimer.Enabled)
            {
                PollTimer          = new System.Timers.Timer(15000);
                PollTimer.Elapsed += (s, e) =>
                {
                    // Send keep alive to all connected clients
                    if (Clients.Count > 0)
                    {
                        Parallel.ForEach(Clients.Values, client => KAHandler.SendKeepAlive(client));
                    }

                    // DisconnectByReason hanging connections
                    if (Processing.Count > 0)
                    {
                        Parallel.ForEach(Processing.Values, client => CheckTimeout(client));
                    }
                };
                PollTimer.Start();
            }

            // Setup timer. Every 5 seconds should be sufficient
            if (StatusTimer == null || !StatusTimer.Enabled)
            {
                StatusTimer          = new System.Timers.Timer(5000);
                StatusTimer.Elapsed += (s, e) =>
                {
                    // Return if we are empty
                    if (PlayerStatusQueue.IsEmpty)
                    {
                        return;
                    }

                    //var transaction =DB.BeginTransaction();

                    try
                    {
                        long       timestamp = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
                        GPCMClient result;
                        while (PlayerStatusQueue.TryDequeue(out result))
                        {
                            // Skip if this player never finished logging in
                            if (result == null)
                            {
                                continue;
                            }

                            if (!result.CompletedLoginProcess)
                            {
                                continue;
                            }
                            LoginQuery.UpdateStatus(timestamp, result.RemoteEndPoint.Address, result.PlayerInfo.PlayerId, (uint)result.PlayerInfo.PlayerStatus);
                        }
                        //transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        LogWriter.Log.WriteException(ex);
                        // transaction.Rollback();
                    }
                };
                StatusTimer.Start();
            }

            // Set connection handling
            ConnectionEnforceMode = EnforceMode.DuringPrepare;

            // TODO: Change this
            //FullErrorMessage = Config.GetValue("Settings", "LoginServerFullMessage").Replace("\"", "");
            FullErrorMessage = "";

            StartAcceptAsync();
        }