示例#1
0
 public void SCAdd(CSClient session, SCAdd message)
 {
     foreach (var c in Program.server.Clients)
     {
         c.Player.Character.Friends.ConnectFriend(message.btName.MakeString(), message.Server);
     }
 }
示例#2
0
 public void SServerList(CSClient session, CSServerList message)
 {
     Program.ServerList = message.List.Take((message.CountH << 8) + message.CountL).Select(x => new MU.Network.Auth.ServerDto {
         type   = x.Type,
         data1  = 32,
         data2  = 0,
         gold   = 0,
         server = x.Index,
     });
 }
示例#3
0
 public void SCRem(CSClient session, SCRem message)
 {
     foreach (var c in Program.server.Clients)
     {
         foreach (var p in message.List)
         {
             c.Player.Character.Friends.DisconnectFriend(p.btName.MakeString());
         }
     }
 }
示例#4
0
        private static void Worker(object param)
        {
            CSClient instance = param as CSClient;

            while (true)
            {
                Thread.Sleep(10000);

                instance.SendAsync(new CKeepAlive {
                    Index = instance.Index, Load = (byte)instance._server.Load, Token = instance._token
                });
            }
        }
示例#5
0
 public void SCAdd(CSClient session, SCAdd message)
 {
     foreach (var c in Program.server.Clients.Where(x => x.Player != null && x.Player.Status == MU.Resources.LoginStatus.Playing))
     {
         var name = message.btName.MakeString();
         c.Player.Character.Friends.ConnectFriend(name, message.Server);
         var m = c.Player.Character.Guild?.Find(name) ?? null;
         if (m != null && message.Server != Program.ServerCode)
         {
             m.Server = message.Server;
         }
     }
 }
示例#6
0
 public void SCRem(CSClient session, SCRem message)
 {
     foreach (var c in Program.server.Clients.Where(x => x.Player != null && x.Player.Status == MU.Resources.LoginStatus.Playing))
     {
         foreach (var p in message.List)
         {
             var name = p.btName.MakeString();
             c.Player.Character?.Friends.DisconnectFriend(name);
             var m = c.Player.Character.Guild?.Find(name) ?? null;
             if (m != null && message.Server != Program.ServerCode)
             {
                 m.Server = 0xff;
             }
         }
     }
 }
示例#7
0
        private static async void ReceiveCallback(IAsyncResult ar)
        {
            CSClient instance = ar.AsyncState as CSClient;
            var      messages = new List <object>();

            try
            {
                var btRecived = instance._client.Client.EndReceive(ar);

                if (btRecived == 0)
                {
                    instance._client.Client.Disconnect(false);
                    return;
                }
                //Logger.Information($"Receive " + btRecived + " Buffer:" + string.Join("", instance._buffer.Select(x => x.ToString("X2"))));
                using (var mem = new MemoryStream(instance._buffer, 0, btRecived))
                {
                    int readed = 0;
                    do
                    {
                        short serial;
                        readed += instance._decoder.Decode(mem, out serial, messages);
                    } while (readed < mem.Length);
                }

                foreach (var message in messages)
                {
                    foreach (var handler in instance._handler)
                    {
                        await handler.OnMessageReceived(instance, message);
                    }
                }

                instance._client.Client
                .BeginReceive(instance._buffer, 0, 1024, SocketFlags.None, ReceiveCallback, instance);
            }
            catch (Exception)
            {
                instance._client.Client.Disconnect(false);
            }
        }
示例#8
0
        private static void ReceiveCallback(IAsyncResult ar)
        {
            CSClient instance = ar.AsyncState as CSClient;
            var      messages = new List <object>();

            try
            {
                var btRecived = instance._client.Client.EndReceive(ar);

                if (btRecived == 0)
                {
                    instance._client.Client.Disconnect(false);
                    return;
                }

                using (var mem = new MemoryStream(instance._buffer, 0, btRecived))
                {
                    int readed = 0;
                    do
                    {
                        short serial;
                        readed += instance._decoder.Decode(mem, out serial, messages);
                    } while (readed < mem.Length);
                }

                foreach (var message in messages)
                {
                    foreach (var handler in instance._handler)
                    {
                        handler.OnMessageReceived(instance, message);
                    }
                }
            }
            catch (Exception)
            {
                instance._client.Client.Disconnect(false);
            }
        }