示例#1
0
        public override void ProcessClient(Client c)
        {
            ByteMessage byteMessage = c.GetByteMessage();

            switch (byteMessage.ReadTag())
            {
            case "CRD":
                string username = byteMessage.ReadString();
                string password = byteMessage.ReadString();
                Console.WriteLine("Incoming credentials: Username {0}, Password {1}, Clients logging in: {2}", username, password, clients.Count);

                // Successfully received credentials, tell user it's allright, give it an id and transfer it to the game service
                ByteMessage ok = new ByteMessage();
                ok.WriteTag("LOK");
                ok.WriteInt(id);
                var x = 3.0f;
                var z = 3.0f;
                ok.WriteFloat(x);     // x
                ok.WriteFloat(z);     // z
                c.id = id;
                c.transform.setPosition(new Vector2(x, z));
                id++;
                c.SendMessage(ok);
                //c.Load();
                SslTcpServer.ServiceBay.gameService.ReceiveClient(c);
                DropClient(c);
                break;
            }
        }
示例#2
0
        public override void OnServiceLeave(Client c)
        {
            ByteMessage msg = new ByteMessage();

            msg.WriteTag("DEP");
            msg.WriteInt(c.id);

            // Delete client in every player's context
            foreach (Client c2 in clients)
            {
                c2.SendMessage(msg);
            }
        }
示例#3
0
        public override void OnServiceEnter(Client c)
        {
            ByteMessage msg = new ByteMessage();

            msg.WriteTag("NEP");
            msg.WriteInt(c.id);
            msg.WriteFloat(1.0f);
            msg.WriteFloat(1.0f);
            // Player generation
            foreach (Client c2 in clients)
            {
                c2.SendMessage(msg);
                // Create every player pawns in the incoming player's context;
                ByteMessage msg2 = new ByteMessage();
                msg2.WriteTag("NEP");
                msg2.WriteInt(c2.id);
                msg2.WriteFloat(c2.transform.getPosition().X);
                msg2.WriteFloat(c2.transform.getPosition().Y);
                c.SendMessage(msg2);
                // Create new player in every other player's context;
            }

            // NPCs generation
            foreach (NPC npc in npcs)
            {
                ByteMessage msg2 = new ByteMessage();
                msg2.WriteTag("NEN");
                msg2.WriteInt(npc.id);
                msg2.WriteFloat(npc.transform.getPosition().X);
                msg2.WriteFloat(npc.transform.getPosition().Y);
                c.SendMessage(msg2);
            }

            // AoE generations

            foreach (AOE aoe in aoes)
            {
                ByteMessage msg2 = new ByteMessage();
                msg2.WriteTag("NEA");
                msg2.WriteInt(aoe.id);
                msg2.WriteFloat(aoe.transform.getPosition().X);
                msg2.WriteFloat(aoe.transform.getPosition().Y);
                c.SendMessage(msg2);
            }
        }
示例#4
0
        public override void Routine(float deltatime)
        {
            // Application des intentions
            foreach (Client c in clients)
            {
                for (int i = 0; i < Client.nbActions; i++)
                {
                    if (c.actions[i] != null)
                    {
                        c.actions[i].Execute(c);
                    }
                }

                c.NullActions();
            }
            // Mise à jour des joueurs
            foreach (Client c in clients)
            {
                c.transform.Update(deltatime);
            }
            // Mise à jour des npcs
            foreach (NPC c in npcs)
            {
                c.Update(deltatime, ref clients, ref npcs, ref aoes);
            }
            // Mise à jour des aoes
            foreach (AOE c in aoes)
            {
                c.Update(deltatime, ref clients, ref npcs, ref aoes);
            }
            // Envoi des mises à jours
            ByteMessage snapshot = new ByteMessage();

            snapshot.WriteTag("SNP");


            // For Each Client
            snapshot.WriteInt(clients.Count);
            foreach (Client c in clients)
            {
                snapshot.WriteInt(c.id);
                snapshot.WriteFloat(c.transform.getPosition().X);
                snapshot.WriteFloat(c.transform.getPosition().Y);
            }

            // For Each Mob
            snapshot.WriteInt(npcs.Count);
            foreach (NPC c in npcs)
            {
                snapshot.WriteInt(c.id);
                snapshot.WriteFloat(c.transform.getPosition().X);
                snapshot.WriteFloat(c.transform.getPosition().Y);
            }

            // For Each AoE
            snapshot.WriteInt(aoes.Count);
            foreach (AOE c in aoes)
            {
                snapshot.WriteInt(c.id);
                snapshot.WriteFloat(c.transform.getPosition().X);
                snapshot.WriteFloat(c.transform.getPosition().Y);
            }

            // Send!

            foreach (Client c in clients)
            {
                c.SendMessage(snapshot);
            }

            // Old update

            /*
             * foreach (Client c in clients)
             * {
             *  ByteMessage msg = new ByteMessage();
             *  msg.WriteTag("UPD");
             *  msg.WriteInt(c.id);
             *  msg.WriteFloat(c.transform.getPosition().X);
             *  msg.WriteFloat(c.transform.getPosition().Y);
             *  foreach (Client c2 in clients) c2.SendMessage(msg);
             *
             * }*/
        }