Beispiel #1
0
    public void Initialise(RakNet.SystemAddress _cSystemAddress, RakNet.RakNetGUID _cGuid, bool _bHost)
    {
        ResetNetworkViewSteam();

        m_cSystemAddress = new RakNet.SystemAddress(_cSystemAddress.ToString(), _cSystemAddress.GetPort());
        m_cGuid          = new RakNet.RakNetGUID(_cGuid.g);
        m_bHost          = _bHost;
    }
Beispiel #2
0
    protected void HandleOnlineServerList(byte[] _baData)
    {
        string sServerList = ASCIIEncoding.ASCII.GetString(_baData, 1, _baData.Length - 1);


        string[] sServer = sServerList.Split('&');


        foreach (string sMyString in sServer)
        {
            if (sMyString.Length > 0)
            {
                RakNet.SystemAddress cServerAddress = new RakNet.SystemAddress(sMyString);


                m_cRnPeer.Ping(cServerAddress.ToString(), cServerAddress.GetPort(), false);
            }
        }
    }
Beispiel #3
0
    void HandleConnectionAccepted(RakNet.SystemAddress _cServerSystemAddress)
    {
        m_fConnectionElapsedTime = 0.0f;
        m_fTick      = 0;
        m_fTickTotal = 0;

        // Only set downloading game state if I am client
        if (!CNetwork.IsServer)
        {
            m_bDownloadingInitialGameState = true;
        }

        // Save server address
        m_cServerSystemAddress = new RakNet.SystemAddress(_cServerSystemAddress.ToString(), _cServerSystemAddress.GetPort());

        // Notify event observers
        if (EventConnectionAccepted != null)
        {
            EventConnectionAccepted();
        }

        Logger.Write("Connection established with server");
    }
        public Task<IConnection> Connect(string endpoint)
        {
            logger.Debug("Connecting to endpoint {0}", endpoint);

            if (_peer == null || !_peer.IsActive())
            {

                throw new InvalidOperationException("Transport not started. Call Start before connect.");
            }
            var infos = endpoint.Split(':');
            var host = infos[0];
            var port = ushort.Parse(infos[1]);
            _peer.Connect(host, port, null, 0);

            var address = new SystemAddress(host, port);

            var tcs = new TaskCompletionSource<IConnection>();

            _pendingConnections.TryAdd(address.ToString(), tcs);

            return tcs.Task;
        }
Beispiel #5
0
	protected void HandleOnlineServerList(byte[] _baData)
	{
		string sServerList = ASCIIEncoding.ASCII.GetString(_baData, 1, _baData.Length - 1);


		string[] sServer = sServerList.Split('&');


		foreach (string sMyString in sServer)
		{
			if (sMyString.Length > 0)
			{
				RakNet.SystemAddress cServerAddress = new RakNet.SystemAddress(sMyString);


				m_cRnPeer.Ping(cServerAddress.ToString(), cServerAddress.GetPort(), false);
			}
		}
	}
Beispiel #6
0
    protected void HandleUnconnectPong(byte[] _baData, RakNet.SystemAddress _cServerSystemAddress, RakNet.RakNetGUID _cServerGuid)
    {
        // Create stream
        CNetworkStream cStream = new CNetworkStream(_baData);

        // Ignore message identifier
        cStream.IgnoreBytes(1);

        // Read time
        uint uiTime = cStream.ReadUInt();

        // Read response data
        byte[] baOfflinePingResponse = cStream.ReadBytes(cStream.NumUnreadBytes);

        // Create server info
        TServer tLanServerInfo = new TServer();

        tLanServerInfo.sIp       = _cServerSystemAddress.ToString();
        tLanServerInfo.usPort    = _cServerSystemAddress.GetPort();
        tLanServerInfo.uiLatency = RakNet.RakNet.GetTimeMS() - uiTime;
        tLanServerInfo.cGuid     = new RakNet.RakNetGUID(_cServerGuid.g);

        // Convert response data to server info
        tLanServerInfo.tServerInfo = new CNetworkServer.TServerInfo(baOfflinePingResponse);


        uint   uiLocalNumberOfAddresses = m_cRnPeer.GetNumberOfAddresses();
        string sIpPrefix    = _cServerSystemAddress.ToString().Substring(0, _cServerSystemAddress.ToString().IndexOf('.'));
        bool   bIsLanServer = false;


        for (uint i = 0; i < uiLocalNumberOfAddresses; ++i)
        {
            string sMyLanIp = m_cRnPeer.GetLocalIP(i);


            string sLanIpPrefix = sMyLanIp.Substring(0, sMyLanIp.IndexOf('.'));


            if (sLanIpPrefix == sIpPrefix)
            {
                bIsLanServer = true;
                break;
            }
        }


        if (!bIsLanServer)
        {
            m_aOnlineServers.Add(tLanServerInfo);
        }
        else
        {
            m_aLanServers.Add(tLanServerInfo);
        }


        //Logger.WriteError("Added server ({0}:({1}) lan ({2})", tLanServerInfo.sIp, tLanServerInfo.usPort, bIsLanServer);


        // Notify event observers
        if (EventFoundServer != null)
        {
            EventFoundServer(tLanServerInfo);
        }
    }