Beispiel #1
0
        static void Main(string[] args)
        {
            string quit = "n";

            while (quit == "n")
            {
                ITransport transport = TcpTransport.CreateTransport(45459);
                if (transport != null)
                {
                    IEvent          e   = new TcpEvent((int)EventId.Media, null);
                    BinaryFormatter bf  = new BinaryFormatter();
                    MemoryStream    mem = new MemoryStream();
                    bf.Serialize(mem, e);
                    transport.Send(mem.GetBuffer());
                    Console.WriteLine("Quit?(y/n)");
                    quit = Console.ReadLine();
                    transport.Close();
                    //if (quit != "n")
                    //{
                    //    Console.WriteLine("send disconned event to Server to close the server");
                    //    IEvent d = new TcpEvent((int)EventId.Disconnect, null);
                    //    BinaryFormatter bfd = new BinaryFormatter();
                    //    MemoryStream memd = new MemoryStream();
                    //    bfd.Serialize(memd, d);
                    //    transport.Send(memd.GetBuffer());
                    //    transport.Close();
                    //}
                }
            }
        }
Beispiel #2
0
        private List <PlayerInfo> MapToPlayerInfo(TcpEvent tcpEvent)
        {
            var packet       = (Packet)tcpEvent.Data;
            var position     = 3;
            var players      = new List <PlayerInfo>();
            var playersCount = packet.Buffer[position++];

            for (byte i = 0; i < playersCount; i++)
            {
                var p = new PlayerInfo();

                p.Id      = Encoding.UTF8.GetString(packet.Buffer, position + 1, packet.Buffer[position]);
                position += packet.Buffer[position];
                position++;

                p.Name    = Encoding.UTF8.GetString(packet.Buffer, position + 1, packet.Buffer[position]);
                position += packet.Buffer[position];
                position++;

                p.Sex       = packet.Buffer[position++];
                p.Level     = packet.Buffer[position++];
                p.Modifiers = packet.Buffer[position++];
                p.Dice      = packet.Buffer[position++];
                players.Add(p);
            }
            return(players);
        }