コード例 #1
0
ファイル: Room.cs プロジェクト: BjkGkh/Custom-R2
 internal void QueueRoomMessage(ServerMessage message)
 {
     lock (roomServerMessages.SyncRoot)
     {
         roomServerMessages.Enqueue(message.GetBytes());
     }
 }
コード例 #2
0
ファイル: Room.cs プロジェクト: BjkGkh/Custom-R2
        internal void SendMessageToUsersWithRights(ServerMessage Message)
        {
            try
            {
                byte[] PacketData = Message.GetBytes();

                foreach (RoomUser user in roomUserManager.UserList.Values)
                {
                    if (user.IsBot)
                        continue;

                    GameClient UsersClient = user.GetClient();
                    if (UsersClient == null)
                        continue;

                    if (!CheckRights(UsersClient))
                        continue;

                    try
                    {
                        UsersClient.GetConnection().SendData(PacketData);
                    }
                    catch (Exception e) { Logging.HandleException(e, "Room.SendMessageToUsersWithRights"); }
                    //User.GetClient().SendMessage(Message);

                }
            }
            catch (Exception e) { Logging.HandleException(e, "Room.SendMessageToUsersWithRights"); }
        }
コード例 #3
0
ファイル: GameClientManager.cs プロジェクト: BjkGkh/Custom-R2
 internal void ModAlert(ServerMessage Message)
 {
     byte[] bytes = Message.GetBytes();
     foreach (GameClient client in clients.Values)
     {
         if (client == null || client.GetHabbo() == null)
         {
             continue;
         }
         if (client.GetHabbo().Rank == 4 || client.GetHabbo().Rank == 5 || client.GetHabbo().Rank == 6)
         try
         {
             client.GetConnection().SendData(bytes);
         }
         catch
         { }
     }
 }
コード例 #4
0
ファイル: GameClientManager.cs プロジェクト: BjkGkh/Custom-R2
        private void TestClientConnections()
        {
            TimeSpan sinceLastTime = DateTime.Now - pingLastExecution;

            if (sinceLastTime.TotalMilliseconds >= pingInterval)
            {
                try
                {
                    ServerMessage PingMessage = new ServerMessage(Outgoing.Ping);

                    List<GameClient> ToPing = new List<GameClient>();
                    //List<GameClient> ToDisconnect = new List<GameClient>();

                    TimeSpan noise;
                    TimeSpan sinceLastPing;

                    foreach (GameClient client in clients.Values)
                    {
                        noise = DateTime.Now - pingLastExecution.AddMilliseconds(pingInterval); //For finding out if there is any lagg
                        sinceLastPing = DateTime.Now - client.TimePingedReceived;

                        if (sinceLastPing.TotalMilliseconds - noise.TotalMilliseconds < pingInterval + 10000)
                        {
                            ToPing.Add(client);
                        }
                        else
                        {
                            lock (timedOutConnections.SyncRoot)
                            {
                                timedOutConnections.Enqueue(client);
                            }
                            //ToDisconnect.Add(client);
                            //Console.WriteLine(client.ConnectionID + " => Connection timed out");
                        }
                    }
                    DateTime start = DateTime.Now;

                    byte[] PingMessageBytes = PingMessage.GetBytes();
                    foreach (GameClient Client in ToPing)
                    {
                        try
                        {
                            if (Client.GetConnection() != null)
                                Client.GetConnection().SendUnsafeData(PingMessageBytes);
                            else
                            {
                                lock (timedOutConnections.SyncRoot)
                                {
                                    timedOutConnections.Enqueue(Client);
                                }
                            }

                        }
                        catch
                        {
                            //ToDisconnect.Add(Client);
                            lock (timedOutConnections.SyncRoot)
                            {
                                timedOutConnections.Enqueue(Client);
                            }
                        }
                    }

                    TimeSpan spent = DateTime.Now - start;
                    if (spent.TotalSeconds > 3)
                    {
                        Console.WriteLine("Spent seconds on testing: " + (int)spent.TotalSeconds);
                    }

                    //start = DateTime.Now;
                    //foreach (GameClient client in ToDisconnect)
                    //{
                    //    try
                    //    {
                    //        client.Disconnect();
                    //    }
                    //    catch { }
                    //}
                    //spent = DateTime.Now - start;
                    if (spent.TotalSeconds > 3)
                    {
                        Console.WriteLine("Spent seconds on disconnecting: " + (int)spent.TotalSeconds);
                    }

                    //ToDisconnect.Clear();
                    //ToDisconnect = null;
                    ToPing.Clear();
                    ToPing = null;

                }
                catch (Exception e) { Logging.LogThreadException(e.ToString(), "Connection checker task"); }
                pingLastExecution = DateTime.Now;
            }
        }
コード例 #5
0
 internal void appendResponse(ServerMessage message)
 {
     appendBytes(message.GetBytes());
 }