Esempio n. 1
0
        private void UpdateClients()
        {
            try
            {
                while (!this.ResetEvent.Wait(200))
                {
                    try
                    {
                        var descriptors = this.ConnectedClients.ToArray();
                        if (descriptors.Length == 0)
                        {
                            continue;
                        }
                        Packet           p       = new Packet();
                        List <TcpClient> sockets = new List <TcpClient>();

                        p.AddUInt16((ushort)descriptors.Length);
                        foreach (ClientDescriptor descriptor in descriptors)
                        {
                            sockets.Add(descriptor.TcpClient);
                            p.AddString(descriptor.PlayerName);
                            p.AddUInt32(descriptor.PlayerID);
                            p.AddUInt16(descriptor.PlayerLevel);
                            p.AddUInt16((ushort)descriptor.Location.X);
                            p.AddUInt16((ushort)descriptor.Location.Y);
                            p.AddByte((byte)descriptor.Location.Z);
                        }
                        p.AddLength();
                        foreach (TcpClient tc in sockets)
                        {
                            if (!tc.Connected)
                            {
                                continue;
                            }
                            p.Send(tc);
                        }
                    }
                    catch { }
                }
            }
            catch { }
        }
Esempio n. 2
0
        private void UpdateClients()
        {
            try
            {
                while (!this.ResetEvent.Wait(200))
                {
                    try
                    {
                        var descriptors = this.ConnectedClients.ToArray();
                        if (descriptors.Length == 0) continue;
                        Packet p = new Packet();
                        List<TcpClient> sockets = new List<TcpClient>();

                        p.AddUInt16((ushort)descriptors.Length);
                        foreach (ClientDescriptor descriptor in descriptors)
                        {
                            sockets.Add(descriptor.TcpClient);
                            p.AddString(descriptor.PlayerName);
                            p.AddUInt32(descriptor.PlayerID);
                            p.AddUInt16(descriptor.PlayerLevel);
                            p.AddUInt16((ushort)descriptor.Location.X);
                            p.AddUInt16((ushort)descriptor.Location.Y);
                            p.AddByte((byte)descriptor.Location.Z);
                        }
                        p.AddLength();
                        foreach (TcpClient tc in sockets)
                        {
                            if (!tc.Connected) continue;
                            p.Send(tc);
                        }
                    }
                    catch { }
                }
            }
            catch { }
        }