private void ManageReferences() { // get reference to the popUp GameObject _connectionPopUp = GameObject.Find("ConnectPopup"); // set reference to play button _playBtn = GameObject.Find("Play Btn").GetComponent <Button>(); // set reference to exit button _exitBtn = GameObject.Find("Exit Btn").GetComponent <Button>(); // reference to the Connect button _connectBtn = GameObject.Find("ConnectBtn").GetComponent <Button>(); // reference to the cancel button _cancelBtn = GameObject.Find("CancelBtn").GetComponent <Button>(); // reference to InputField _playerInputField = GameObject.Find("inputFieldPlayerName").GetComponent <Text>(); // reference to server ip inputField _serverIpInput = GameObject.Find("inputFieldServer").GetComponent <Text>(); // disable PopUp _connectionPopUp.SetActive(false); // set buttons active _playBtn.enabled = true; _exitBtn.enabled = true; // reference to the networkController _netWorkController = GameObject.Find("NetworkController").GetComponent <ClientNetworkController>(); // reference to the connection screen _connectionScreen = GetComponent <ConnectionScreen>(); }
private void menuConnect_Click(object sender, RoutedEventArgs e) { ConnectionScreen cscreen = new ConnectionScreen(); cscreen.Show(); }
public static bool Handshake(string IPAddr, int port, bool anon, string username, string password, ConnectionScreen connSc = null) { if (NetworkManager.receiving == true) { NetworkManager.Disconnect(); return(true); } if (NetworkManager.Connect(IPAddr, port, (bool)anon)) { try { NetworkManager.SendMessage("serverInfoRequest", "", enc: false); Dictionary <string, string> message = NetworkManager.ReceiveMessage(); // Receive serverInfo KeyGenerator.SecretKey = KeyGenerator.GetUniqueKey(16); NetworkManager.SendMessage("clientSecret", EncryptionManager.RSAEncrypt(KeyGenerator.SecretKey, message["data"].ToString()), enc: false); message = NetworkManager.ReceiveMessage(true); // Receive gotSecret string version = ConfigManager.GetSetting("version"); List <string> connRequest = new List <string> { username, password, version }; string jsonConnReq = JsonConvert.SerializeObject(connRequest); NetworkManager.SendMessage("connectionRequest", jsonConnReq); message = NetworkManager.ReceiveMessage(true); if (message["messagetype"] == "CRAccepted") { NetworkManager.ReceiveMessages(); VisualManager.ClearUsers(); VisualManager.ClearChan(); VisualManager.SystemMessage("Handshake complete"); if (connSc != null) { connSc.Close(); } handshakeInfo["ip"] = IPAddr; handshakeInfo["port"] = port; handshakeInfo["username"] = username; handshakeInfo["password"] = password; handshakeInfo["anon"] = anon; return(true); } else if (message["messagetype"] == "CRDenied") { VisualManager.SystemMessage("Connection denied - " + message["data"]); if (connSc != null) { connSc.Close(); } return(false); } return(false); } catch (System.Net.Sockets.SocketException) { VisualManager.SystemMessage("Connection was lost during handshake"); if (connSc != null) { connSc.Close(); } return(false); } } else { VisualManager.SystemMessage("Connection failed"); return(false); } }