Ejemplo n.º 1
0
        protected override void HandleMessage()
        {
            if (ClientHelloMessage.SIs(readBuffer)) {
                int new_id = new ClientHelloMessage(readBuffer).Id;
                Id = new_id;
                Console.WriteLine("connected!");
            }
            if (HelloMessage.SIs(readBuffer)) {
                int new_id = new HelloMessage(readBuffer).Id;

                IUpdateable updateable = waitingForId.Dequeue();
                Type t = updateable.GetType();
                stuff[t][new_id] = updateable;
                if (updateable is Slug) {
                    var slug = (Slug)updateable;
                    SendMessage(new SlugMessage(new_id, slug.Position, slug.Speed, slug.Magnum.Owner.Id));
                } else if (updateable is Gangster) {
                    var gangster = (Gangster)updateable;
                    SendMessage(new GangsterMessage(new_id, gangster.Position));
                }
            } else if (GangsterMessage.SIs(readBuffer)) {
                var gm = new GangsterMessage(readBuffer);
                var gangster = (Gangster)stuff[typeof(Gangster)][gm.Id];
                gangster.Position = gm.Position;
            } else if (SlugMessage.SIs(readBuffer)) {
                var sm = new SlugMessage(readBuffer);
                var slug = (Slug)stuff[typeof(Slug)][sm.Id];
                slug.Position = sm.Position;
                slug.Speed = sm.Velocity;
            }
        }
Ejemplo n.º 2
0
        public void SendHello(ClientDetails visage, Int32 id)
        {
            var message = new ClientHelloMessage(id);

            Console.WriteLine("sending hello");
            visage.client.GetStream().BeginWrite(message.GetBytes(), 0, message.Size, new AsyncCallback(SentHello), visage);
        }