示例#1
0
        private void CreateUser(ClientMessage message)
        {
            Console.WriteLine("Creating user");
            LoginData data = new OperationDataHandler().TranslateObject <LoginData>(message.Operation.OperationData) as LoginData;

            bool result = false;

            DbHandler handler = new DbHandler();

            byte[] passwordHash = new Encryption().EncryptSHA(data.Password, data.Login);

            result = handler.CreateUser(data.Login, passwordHash);

            if (result)
            {
                message.Client.ClientName = data.Login;
            }

            message.Client.SendResponse(new ServerResponse()
            {
                Operations   = message.Operation.Operation,
                IsSuccess    = result,
                ResponseData = new OperationDataHandler().GetBytes(message.Client.ClientName)
            });
            Console.WriteLine("User created");
        }
示例#2
0
        private void PerformLogin(ClientMessage message)
        {
            Console.WriteLine("Loggining user");

            LoginData data = new OperationDataHandler().TranslateObject <LoginData>(message.Operation.OperationData) as LoginData;

            bool result = false;

            DbHandler handler = new DbHandler();

            result = handler.CheckExistingUser(data.Login, data.Password);

            result = result && this.ClientsList.Values.Cast <ConnectedClient>().All(c => c.ClientName != data.Login);

            if (result)
            {
                message.Client.ClientName = data.Login;
            }

            message.Client.SendResponse(new ServerResponse()
            {
                Operations   = message.Operation.Operation,
                IsSuccess    = result,
                ResponseData = new OperationDataHandler().GetBytes(data.Login)
            });

            Console.WriteLine("User logedin");
        }
示例#3
0
        private void HandleServerResponse()
        {
            ArrayList responseData = new ArrayList();

            while (true)
            {
                lock (this.lockObject)
                {
                    Int32 bytes = -1;
                    while (this.Client.GetStream().DataAvailable)
                    {
                        var data = new Byte[2048];

                        bytes = this.SslStream.Read(data, 0, data.Length);
                        responseData.AddRange(data);
                    }
                }

                if (responseData.Count != 0)
                {
                    ServerResponse response = new OperationDataHandler()
                                              .TranslateObject <ServerResponse>((byte[])responseData.ToArray(typeof(byte)));
                    this.HandleOperationResult(response);
                    responseData.Clear();
                }
            }
        }
示例#4
0
        public DataTable GetOperation()
        {
            OperationDataHandler dh = new OperationDataHandler();

            datat = dh.ReadOperation("Operations");

            return(datat);
        }
示例#5
0
        public DataTable GetsearchedOperations(int operationID)
        {
            OperationDataHandler dh = new OperationDataHandler();

            searchOperatios = dh.SearchOperation("Operations", operationID);

            return(searchOperatios);
        }
示例#6
0
        public DataTable GetAllOperations()
        {
            OperationDataHandler dh = new OperationDataHandler();

            allOperation = dh.AllOperations("Operations");

            return(allOperation);
        }
示例#7
0
        private ClientRequestData TranslateMessage(ArrayList message)
        {
            byte[] data = (byte[])message.ToArray(typeof(byte));

            ClientRequestData requestData =
                new OperationDataHandler().TranslateObject <ClientRequestData>(data) as ClientRequestData;

            return(requestData);
        }
示例#8
0
        public void FindBatle()
        {
            var opHandler = new OperationDataHandler();

            byte[] data = opHandler.GetBytes(new ClientRequestData(ClientOperationsType.FindBattle, null));


            // Send the message to the connected TcpServer.
            this.WriteData(data);
        }
示例#9
0
        public List <Operation> ReadOperations()
        {
            DataSet OperationDate = new OperationDataHandler().ReadOperations("Operations");

            foreach (DataRow item in OperationDate.Tables["Operations"].Rows)
            {
                GetOperations.Add(new Operation(int.Parse(item["OperationID"].ToString()), item["OperationType"].ToString(), DateTime.Parse(item["OperationDate"].ToString()), item["OperationType"].ToString()));
            }

            return(GetOperations);
        }
示例#10
0
        public void PerformLogin(string login, string password)
        {
            var opHandler = new OperationDataHandler();

            byte[] data = opHandler.GetBytes(new ClientRequestData(ClientOperationsType.Login,
                                                                   opHandler.GetBytes(new LoginData(login, password))));

            // Send the message to the connected TcpServer.
            this.WriteData(data);

            this.LoginStatus = LoginStatus.Loggining;
        }
示例#11
0
        public void MakeBattleMove(BattleMoveData moveData)
        {
            moveData.BattleId = this.BattleId;

            var opHandler = new OperationDataHandler();

            byte[] data = opHandler.GetBytes(new ClientRequestData(ClientOperationsType.SendBattleTurn, opHandler.GetBytes(moveData)));


            // Send the message to the connected TcpServer.
            this.WriteData(data);

            this.BattleStatus = BattleStatus.Wait;
        }
示例#12
0
        private void HandleBattleFound(ServerResponse response)
        {
            this.BattleStatus = BattleStatus.Battle;

            var opHandler = new OperationDataHandler();

            NewBattleData battleData = opHandler.TranslateObject <NewBattleData>(response.ResponseData);

            this.BattleId = battleData.BattleId;
            this.OnBatteStatusChanged(new BattleStatusData()
            {
                BattleStatus  = BattleStatus.Battle,
                NewBattleData = battleData
            });
        }
示例#13
0
 public void SendResponse(ServerResponse response)
 {
     lock (this.sslStreamLockobject)
     {
         var    stream = this.sslStream;
         byte[] data   = new OperationDataHandler().GetBytes(response);
         try
         {
             stream.Write(data, 0, data.Length);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
 }
示例#14
0
        private void HandleBattleTurn(ServerResponse response)
        {
            BattleResponseData moveResult = new OperationDataHandler().TranslateObject <BattleResponseData>(response.ResponseData);

            if (!moveResult.IsBattleContinue)
            {
                this.BattleStatus = response.IsSuccess ? BattleStatus.Victory : BattleStatus.Defeat;
                return;
            }

            this.BattleStatus = BattleStatus.Battle;

            this.OnBatteStatusChanged(new BattleStatusData()
            {
                BattleStatus = BattleStatus.Battle,
                ResponseData = moveResult
            });
        }
示例#15
0
        public void ProcessBattleMove(ClientMessage data)
        {
            var opHandler = new OperationDataHandler();

            BattleMoveData moveData = opHandler.TranslateObject <BattleMoveData>(data.Operation.OperationData);

            Battle battleToProcess = this.ActiveBattles.FirstOrDefault(x => x.BattleId.Equals(moveData.BattleId));

            if (battleToProcess != null)
            {
                battleToProcess.MakeMove(data.Client, moveData.Attack, moveData.Defence, moveData.TargetName);

                if (battleToProcess.IsBattleEnded)
                {
                    this.ActiveBattles.Remove(battleToProcess);
                    battleToProcess = null;
                }
            }
        }