public bool ConnectToServer(string _sServerIp, ushort _usServerPort, string _sServerPassword) { bool bConnectionStarted = false; // Set empty password for null password if (_sServerPassword == null) { _sServerPassword = ""; } // Terminate current connection Disconnect(); // Connect the server RakNet.ConnectionAttemptResult eConnectionAttempResult = m_cRnPeer.Connect(_sServerIp, _usServerPort, _sServerPassword, _sServerPassword.Length); // Ensure connection started if (eConnectionAttempResult != RakNet.ConnectionAttemptResult.CONNECTION_ATTEMPT_STARTED) { Logger.WriteError("Connection to server attempt failed. ErrorCode({0})", eConnectionAttempResult); } else { bConnectionStarted = true; Logger.Write("Connection request sent. ServerIp({0}) ServerPort({1}) ServerPassword({2})", _sServerIp, _usServerPort, _sServerPassword); } return(bConnectionStarted); }
void ConnectToMasterServer() { // Terminate current connection ShutdownPeer(); // Connect the server RakNet.ConnectionAttemptResult eConnectionAttempResult = m_cRnPeer.Connect(CNetwork.sMasterServerIp, CNetwork.usMasterServerPort, CNetwork.sMasterServerPassword, CNetwork.sMasterServerPassword.Length); // Ensure connection started if (eConnectionAttempResult != RakNet.ConnectionAttemptResult.CONNECTION_ATTEMPT_STARTED) { Logger.WriteError("Master server connection to server attempt failed. ErrorCode({0})", eConnectionAttempResult); if (EventConnectionError != null) { // Notify observer's EventConnectionError(); } } else { //Logger.Write("Master server connection request sent. ServerIp({0}) ServerPort({1}) ServerPassword({2})", CNetwork.sMasterServerIp, CNetwork.usMasterServerPort, CNetwork.sMasterServerPassword); } }
public RakNet.ConnectionAttemptResult Connect(string ip, ushort remotePort, string password) { _ServerIP = ip; _ServerPort = remotePort; _ConnectPassword = password; RakNet.ConnectionAttemptResult result = _peer.Connect(_ServerIP, _ServerPort, _ConnectPassword, _ConnectPassword.Length); if (result == RakNet.ConnectionAttemptResult.CONNECTION_ATTEMPT_STARTED) { _bHasConnectSuccess = true; } return(result); }