private static void ModifyPassword(JToken accountInfo, Socket clientSocket) { string account = accountInfo[JsonPackageKeys.Account].ToString(); string newPassword = accountInfo[JsonPackageKeys.Password].ToString(); SqlExecutor.ModifyPassword(account, newPassword); Communication.Send(clientSocket, JsonPackageKeys.Success, ""); }
private static void Login(JToken accountInfo, Socket clientSocket, BackgroundWorker worker) { string account = accountInfo[JsonPackageKeys.Account].ToString(); if (!SqlExecutor.Exists(account)) { object errorMessage = new { DetailedError = JsonPackageKeys.NoSuchAccount }; Communication.Send(clientSocket, JsonPackageKeys.Error, errorMessage); } else { string password = accountInfo[JsonPackageKeys.Password].ToString(); if (!SqlExecutor.ValidatePassword(account, password)) { object errorMessage = new { DetailedError = JsonPackageKeys.WrongPassword }; Communication.Send(clientSocket, JsonPackageKeys.Error, errorMessage); } else { // Add the new online user to online user list. ClientInfo client = new ClientInfo { Account = account, ClientSocket = clientSocket, State = ClientState.Idle, Worker = worker }; clientInfos.Enqueue(client); Communication.Send(clientSocket, JsonPackageKeys.Success, ""); } } }
private static void Register(JToken accountInfo, Socket clientSocket) { string account = accountInfo[JsonPackageKeys.Account].ToString(); // Send error message if the account name already exits. // Otherwise, create the account. if (SqlExecutor.Exists(account)) { object errorMessage = new { DetailedError = JsonPackageKeys.AccountAlreadyExists }; Communication.Send(clientSocket, JsonPackageKeys.Error, errorMessage); } else { string password = accountInfo[JsonPackageKeys.Password].ToString(); string mailAddress = accountInfo[JsonPackageKeys.MailAddress].ToString(); SqlExecutor.CreateAccount(account, password, mailAddress); Communication.Send(clientSocket, JsonPackageKeys.Success, ""); } }