当前位置: 首页>>代码示例>>C#>>正文


C# ServerMessage.GetBytes方法代码示例

本文整理汇总了C#中Firewind.Messages.ServerMessage.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# ServerMessage.GetBytes方法的具体用法?C# ServerMessage.GetBytes怎么用?C# ServerMessage.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Firewind.Messages.ServerMessage的用法示例。


在下文中一共展示了ServerMessage.GetBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendMessageToUsersWithRights

        internal void SendMessageToUsersWithRights(ServerMessage Message)
        {
            try
            {
                byte[] PacketData = Message.GetBytes();

                foreach (RoomUnit unit in roomUserManager.UnitList.Values)
                {
                    RoomUser user = unit as RoomUser;
                    if (user == null)
                        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"); }
        }
开发者ID:Kristopher-RZ,项目名称:Firewind,代码行数:30,代码来源:Room.cs

示例2: TestClientConnections

        private void TestClientConnections()
        {
            try
            {
                DateTime startTaskTime;
                TimeSpan spentTime;
                startTaskTime = DateTime.Now;
                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);
                                // pa ver los timeouts por si sale alguno mas por algun motivo
                                Logging.WriteLine(client.ConnectionID + " => Connection timed out");
                            }
                        }
                        DateTime start = DateTime.Now;

                        byte[] PingMessageBytes = PingMessage.GetBytes();
                        foreach (GameClient Client in ToPing)
                        {
                            try
                            {
                                Client.GetConnection().SendUnsafeData(PingMessageBytes);
                            }
                            catch
                            {
                                //Logging.LogCriticalException("Failed to send ping packet, possible fack up!");
                                //ToDisconnect.Add(Client);
                                lock (timedOutConnections.SyncRoot)
                                {
                                    timedOutConnections.Enqueue(Client);
                                }
                            }
                        }

                        TimeSpan spent = DateTime.Now - start;
                        if (spent.TotalSeconds > 3)
                        {
                            Logging.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)
                        {
                            Logging.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;
                }
                spentTime = DateTime.Now - startTaskTime;

                if (spentTime.TotalSeconds > 3)
                {
                    Logging.WriteLine("GameClientManager.TestClientConnections spent: " + spentTime.TotalSeconds + " seconds in working.");
                }
            }
            catch (Exception e) { Logging.LogThreadException(e.ToString(), "GameClientManager.TestClientConnections Exception --> Not inclusive"); }
        }
开发者ID:Kristopher-RZ,项目名称:Firewind,代码行数:100,代码来源:GameClientManager.cs

示例3: SendMessage

        internal void SendMessage(ServerMessage Message)
        {
            try
            {
                if (Message == null)
                    return;
                //Logging.WriteLine("Sended message to all people: " + FirewindEnvironment.GetDefaultEncoding().GetString(Message.GetBytes()).Replace(Convert.ToChar(0).ToString(), "{char0}"));
                byte[] PacketData = Message.GetBytes();

                lock (roomServerMessages.SyncRoot)
                {
                    roomServerMessages.Enqueue(PacketData);
                }
            }
            catch (InvalidOperationException e) { Logging.HandleException(e, "Room.SendMessage"); }
        }
开发者ID:Kristopher-RZ,项目名称:Firewind,代码行数:16,代码来源:Room.cs

示例4: QueueRoomMessage

 internal void QueueRoomMessage(ServerMessage message)
 {
     lock (roomServerMessages.SyncRoot)
     {
         roomServerMessages.Enqueue(message.GetBytes());
     }
 }
开发者ID:Kristopher-RZ,项目名称:Firewind,代码行数:7,代码来源:Room.cs

示例5: UnsafeSendMessage

 internal void UnsafeSendMessage(ServerMessage Message)
 {
     if (Message == null)
         return;
     if (GetConnection() == null)
         return;
     GetConnection().SendUnsafeData(Message.GetBytes());
 }
开发者ID:TheNaked,项目名称:Firewind,代码行数:8,代码来源:GameClient.cs

示例6: SendBanMessage

 internal void SendBanMessage(string Message)
 {
     ServerMessage BanMessage = new ServerMessage(Outgoing.DisconnectReason);
     //BanMessage.AppendStringWithBreak(LanguageLocale.GetValue("moderation.banmessage"), 13);
     //BanMessage.AppendString(Message);
     BanMessage.AppendInt32(10);
     GetConnection().SendData(BanMessage.GetBytes());
 }
开发者ID:TheNaked,项目名称:Firewind,代码行数:8,代码来源:GameClient.cs

示例7: appendResponse

 internal void appendResponse(ServerMessage message)
 {
     appendBytes(message.GetBytes());
 }
开发者ID:TheNaked,项目名称:Firewind,代码行数:4,代码来源:QueuedServerMessage.cs


注:本文中的Firewind.Messages.ServerMessage.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。