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"); }
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"); }
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(); } } }
public DataTable GetOperation() { OperationDataHandler dh = new OperationDataHandler(); datat = dh.ReadOperation("Operations"); return(datat); }
public DataTable GetsearchedOperations(int operationID) { OperationDataHandler dh = new OperationDataHandler(); searchOperatios = dh.SearchOperation("Operations", operationID); return(searchOperatios); }
public DataTable GetAllOperations() { OperationDataHandler dh = new OperationDataHandler(); allOperation = dh.AllOperations("Operations"); return(allOperation); }
private ClientRequestData TranslateMessage(ArrayList message) { byte[] data = (byte[])message.ToArray(typeof(byte)); ClientRequestData requestData = new OperationDataHandler().TranslateObject <ClientRequestData>(data) as ClientRequestData; return(requestData); }
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); }
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); }
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; }
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; }
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 }); }
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); } } }
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 }); }
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; } } }