internal void HandleConnection() { try { bw.Write(sessionID); while (true) { HandleNonLoggedInRequests(); HandleLoggedInRequests(); } } catch (SerializationException e) { if (loggedIn) { server.loggedInUsers.Remove(loggedUser); server.database.MakeOffline(loggedUser); server.writersPerUsername.TryRemove(loggedUser, out var writer); server.database.UnloadContacts(loggedUser); writer.Close(); loggedIn = false; // not neccessary } } catch (Exception e) { Console.Error.WriteLine("Exception -> {}", e); } finally { server.activeSessions.Remove(this.sessionID); } }
private void CreateGroupChat(object sender, EventArgs e) { var users = new List <Username>(collection.Count); Navigation.PopModalAsync(animated: true); Task.Run(() => { string val; for (int i = 0; i < collection.Count; i++) { val = collection[i].value.Trim(); if (val.Length == 0) { Device.InvokeOnMainThreadAsync(() => DisplayAlert("Error", "No username has empty username.", "Okay")); users = null; return; } users.Add(val.ToUsername()); } var set = users.ToHashSet(); if (set.Count >= 2) { writer.Write(new NewChatRequest(myUsername, users.ToArray(), sessionID)); } }); }
private void ChangePasswordButton_Clicked(object sender, EventArgs e) { if (oldPasswordEntry.Text.Length > 0 && newPasswordEntry.Text.Length > 0 && newPasswordCheckEntry.Text.Length > 0 ) { if (newPasswordEntry.Text == newPasswordCheckEntry.Text) { //Task.Run( () => //{ writer.Write(new ChangePasswordRequest(myUsername, oldPasswordEntry.Text, newPasswordEntry.Text, sessionID)); //}); Navigation.PopAsync(animated: true); } else { DisplayAlert("New password error", "New passwords do not match.", "Okay"); } } else { DisplayAlert("Password format error", "Password cannot be empty text.", "Okay"); } }
private void button_Clicked(object sender, EventArgs e) { if (editor.Text.Length > 0) { string text = editor.Text.Trim(); editor.Text = string.Empty; Task.Run(() => writer.Write(new NewMessageRequest(info.Type, info.ID, new TextMessage(myUsername, info.ID, text), sessionID)) ); } }
private void Button_Clicked(object sender, EventArgs e) { if (usernameEntry.Text.Trim().Length > 0) { var usr = usernameEntry.Text.Trim(); Navigation.PopModalAsync(animated: true); Task.Run(() => { var req = new NewChatRequest(myUsername, usr.ToUsername(), sessionID); writer.Write(req); }); } }
public virtual void Write(BinaryFormatterWriter output) { output.Write((byte)1); output.Write(this.ObjectId); output.Write(this.MapId); }
private void DeleteMessageButton_Clicked(object sender, EventArgs e) { writer.Write(new DeleteMessageRequest(chatType, msg.ChatID, msg, sessionID)); Navigation.PopAsync(animated: true); }
private void loginBtn_Clicked(object sender, EventArgs e) { indicator.IsVisible = true; indicator.IsRunning = true; //Task.Run(() => { try{ if (!client.Connected) { client = Connection.Connect(hostname, defaultPort, ref writer, ref reader); sessionID = (long)reader.Read(); } var username = usernameEntry.Text.Trim().ToUsername(); var password = passwordEntry.Text.ToPassword(); SignInRequest req = new SignInRequest(username, password, sessionID); writer.Write(req); //req.Send(writer); Response resp = (Response)reader.Read(); if (resp.SessionID == sessionID) { //switch ((ResponseType)Enum.Parse(typeof(ResponseType), (string)reader.Read())) switch (resp.Type) { case ResponseType.AccountInfo: AccountInfoResponse AIResp = (AccountInfoResponse)resp; //.Read(reader, sessionID); var homePage = new NavigationPage(new HomePage(app, username, writer, reader, AIResp, sessionID)); //Device.BeginInvokeOnMainThread(() => { //indicator.IsVisible = false; //indicator.IsRunning = false; app.MainPage = homePage; //}); break; case ResponseType.Fail: FailResponse FResp = (FailResponse)resp; //.Read(reader, sessionID); DisplayAlert(SignInFailTitle, FResp.Reason, DefaultCancel); break; default: throw new InvalidResponseException(); } } else { Connection.Disconnect(ref client, ref reader, ref writer); } } catch (SocketException) { DisplayAlert(ConnectionErrorTitle, ConnectionErrorMessage, DefaultCancel); } catch (InvalidResponseException) { //Task.Run( () => DisplayAlert(ResponseErrorTitle, ResponseErrorMessage, DefaultCancel); //); } finally { indicator.IsVisible = false; indicator.IsRunning = false; } //}); }