Exemplo n.º 1
0
        //
        // On attends que le client nous dise s'il veut faire un donjon, auquel cas on le redirige vers un service approprié
        //
        public override void ProcessClient(Client c)
        {
            ByteMessage byteMessage = c.GetByteMessage();

            switch (byteMessage.ReadTag())
            {
            case "OMV":     // Movement intent
            {
                int          id       = byteMessage.ReadInt();
                int          segments = byteMessage.ReadInt();
                List <float> dx       = new List <float>();
                List <float> dy       = new List <float>();
                List <float> rx       = new List <float>();
                List <float> ry       = new List <float>();
                List <float> time     = new List <float>();
                for (int i = 0; i < segments; i++)
                {
                    dx.Add(byteMessage.ReadFloat());
                    dy.Add(byteMessage.ReadFloat());
                    rx.Add(byteMessage.ReadFloat());
                    ry.Add(byteMessage.ReadFloat());
                    time.Add(byteMessage.ReadFloat());
                }
                c.actions[0] = new Actions.MoveAction(dx, dy, rx, ry, time);
            }
            break;

            case "PNG":
            {
                c.HeartBeat();
            }
            break;
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
 public void SendMessage(ByteMessage msg)
 {
     try
     {
         stream.Write(msg.GetMessage());
     }
     catch (Exception e)
     {
     }
 }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public static void Populate(List <Tuple <string, ByteMessage, ByteMessage> > mapsToBake)
        {
            NavigationBuilder.Initialize();
            foreach (var mapdata in mapsToBake)
            {
                ByteMessage map = mapdata.Item2;
                //map.Load("D:/Database/Maps/default");
                string name   = mapdata.Item1;
                int    nbVert = map.ReadInt();

                Vector3[] verts = new Vector3[nbVert];

                for (int i = 0; i < nbVert; i++)
                {
                    verts[i] = new Vector3(map.ReadFloat(), map.ReadFloat(), map.ReadFloat());
                }


                int   nbInd = map.ReadInt();
                int[] inds  = new int[nbInd];

                for (int i = 0; i < nbInd; i++)
                {
                    inds[i] = map.ReadInt();
                }

                int nbPg = map.ReadInt();
                List <NavigationBuilder.PointGraph> pts = new List <NavigationBuilder.PointGraph>();

                for (int i = 0; i < nbPg; i++)
                {
                    NavigationBuilder.PointGraph p = new NavigationBuilder.PointGraph();
                    p.index      = map.ReadInt();
                    p.neighbours = new List <int>();

                    int nbNei = map.ReadInt();

                    for (int j = 0; j < nbNei; j++)
                    {
                        p.neighbours.Add(map.ReadInt());
                    }

                    pts.Add(p);
                }



                NavigationBuilder.AddMap(name, verts, inds, pts);
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        public override void ProcessClient(Client c)
        {
            ByteMessage byteMessage = c.GetByteMessage();

            switch (byteMessage.ReadTag())
            {
            case "VER":
                string version = byteMessage.ReadString();
                Console.WriteLine("Client Version: {0}", version);

                SslTcpServer.ServiceBay.loginService.ReceiveClient(c);

                //Sends user to the login service and ask for credentials (AFC)
                ByteMessage creds = new ByteMessage();
                creds.WriteTag("AFC");
                c.SendMessage(creds);

                DropClient(c);
                break;
            }
        }
Exemplo n.º 8
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);
             *
             * }*/
        }