/// <summary> /// Update /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Update(ConnectionModel model) { try { var repo = new ConnectionsRepository(); return(repo.Update(model)); } catch (Exception ex) { throw ex; } }
public void ListenForConnectionRequests() { Console.WriteLine("Listening for connection requests..."); while (listener != null) { if (listener.Pending()) { Connection conn = new Connection(listener.AcceptTcpClient(), false); ConnectionsRepository.AddConnection(conn, false); conn.DataTransfered += DataProcessor.ProcessData; conn.InitializeDataListener(); Console.WriteLine("New connection accepted."); } } }
public static void Shutdown() { if (online) { connectionHandler.Reset(); ConnectionsRepository.Reset(); foreach (PlayerAccount account in PlayerHandler.GetPlayers()) { AccountFileHandler.SaveAccount(account); } listener.Stop(); thread.Abort(); Console.WriteLine("Server has shut down."); } else { Console.WriteLine("Failed since the server isn't online."); } }
private void loginButton_Click(object sender, EventArgs e) { if (!ValidLoginInput()) { return; } try { TcpClient client = new TcpClient(); client.Connect(ipAddress, port); Connection conn = new Connection(client, true); conn.SendData(new AuthenticationRequest(GetUsername(), GetPassword())); AuthenticationResponse authentication = (AuthenticationResponse)conn.ReceiveData(); if (authentication.Message == null) { ConnectionsRepository.AddConnection(conn, true); conn.DataTransfered += DataProcessor.ProcessData; conn.InitializeDataListener(); this.Visible = false; this.ShowInTaskbar = false; GameForm game = new GameForm(conn); conn.ShutdownRequest += ServerDown; game.FormClosed += CloseClient; game.Show(); } else { noteLabel.Text = authentication.Message; } } catch { noteLabel.Text = "No response from server."; } }
private void GameForm_FormClosed(object sender, FormClosedEventArgs e) { ConnectionsRepository.RemoveConnection(conn); }