Esempio n. 1
0
            public void Connect(TcpClient socket)
            {
                this.socket = socket;
                socket.ReceiveBufferSize = dataBufferSize;
                socket.SendBufferSize    = dataBufferSize;

                stream = socket.GetStream();

                receiveData   = new Packet();
                receiveBuffer = new byte[dataBufferSize];

                stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);

                ServerSend.Welcome(id, "welcome to server!");
            }
Esempio n. 2
0
        public static void AddBuilding(int fromClient, Packet packet)
        {
            int baseID   = packet.ReadInt();
            var instance = packet.ReadBuildingInstanceData();
            int oldID    = instance.ID;
            int newID;

            using (var provider = new ServiceProvider())
            {
                provider.AddBuilding(instance);
                var baseData = provider.BaseDataService.Get(baseID);
                baseData.Buildings.Add(instance);
                provider.SaveChanges();
                newID = instance.ID;
            }

            ServerSend.BuildingAdded(fromClient, oldID, newID);
        }
Esempio n. 3
0
        public static void SubtractGems(int fromClient, Packet packet)
        {
            string username = packet.ReadString();
            int    gems     = packet.ReadInt();

            if (gems <= 0)
            {
                Console.WriteLine("Gems must be positive!");
                return;
            }

            using (var provider = new ServiceProvider())
            {
                var player = provider.PlayerDataService.Get(username);
                player.Gems -= gems;
                provider.SaveChanges();
            }

            ServerSend.UpdateGems(fromClient, username);
        }
Esempio n. 4
0
        public static void LoginRequested(int fromClient, Packet packet)
        {
            string username = packet.ReadString();
            int    pasLen   = packet.ReadInt();

            byte[] password = packet.ReadBytes(pasLen);

            using (var provider = new ServiceProvider())
            {
                var player = provider.PlayerDataService.Login(username, password);
                if (player == null)
                {
                    Console.WriteLine("Player failed to Log In");
                }
                else
                {
                    Console.WriteLine("Player successfully logged in");
                }
                Server.clients[fromClient].player = player;
                ServerSend.LoadPlayer(fromClient, player);
            }
        }
Esempio n. 5
0
        public static void RequestFewRandomBases(int fromClient, Packet packet)
        {
            int        count    = packet.ReadInt();
            string     username = packet.ReadString();
            List <int> options;

            using (var provider = new ServiceProvider())
            {
                var player = provider.PlayerDataService.Get(username);
                options = provider.BaseDataService
                          .Find(b => (b.Player.Username != username))
                          .TakeWhile(data => (count--) > 0)
                          .Select(data => data.ID).ToList();
                for (int i = options.Count - 1; i > -1; i--)
                {
                    if (provider.BaseDataService.IsDestroyed(options[i]))
                    {
                        options.RemoveAt(i);
                    }
                }
            }

            ServerSend.GiveFewRandomBases(fromClient, options);
        }
Esempio n. 6
0
        public static void RequestAttackableBaseData(int fromClient, Packet packet)
        {
            int id = packet.ReadInt();

            ServerSend.GiveBaseToAttackData(fromClient, id);
        }