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; }
public void StartRakNetClient() { RakNetSocket socket = RakNet.CreateClient(new IPEndPoint(IPAddress.Any, 19132)); //client.OnReceive = packet => { Console.WriteLine(packet.ReadByte()); }; RakNetPacket p = socket.ReceivePacketAsync().GetAwaiter().GetResult(); if (p is UnconnectedPing unconnectedPing) { Console.WriteLine(p.PacketId); Console.WriteLine(unconnectedPing.TimeStamp); Console.WriteLine(unconnectedPing.PingId); } }
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"); }
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); } }
protected void HandleConnectionAccepted(RakNet.SystemAddress _cServerSystemAddress) { m_cMasterServerAddress = _cServerSystemAddress; //Logger.WriteError("Our master server connection was accepted"); }
protected void HandlePlayerMicrophoneAudio(RakNet.RakNetGUID _cPlayerGuid, byte[] _baData) { if (EventRecievedPlayerMicrophoneAudio != null) { CNetworkStream cAudioDataStream = new CNetworkStream(_baData); cAudioDataStream.IgnoreBytes(1); EventRecievedPlayerMicrophoneAudio(FindNetworkPlayer(_cPlayerGuid.g), cAudioDataStream); } }
protected void HandlePlayerSerializedData(RakNet.RakNetGUID _cPlayerGuid, byte[] _baData) { CNetworkPlayer cNetworkPlayer = s_mNetworkPlayers[_cPlayerGuid.g]; CNetworkConnection.ProcessPlayerSerializedData(cNetworkPlayer, _baData); }
protected void HandlePlayerConnect(RakNet.SystemAddress _cSystemAddress, RakNet.RakNetGUID _cGuid) { // Create network player instance for new player CNetworkPlayer cNetworkPlayer = gameObject.AddComponent<CNetworkPlayer>(); // Check is host by matching address and connection guid bool bIsHost = _cGuid.g == CNetwork.Connection.RakPeer.GetMyGUID().g; // Initialise player instance cNetworkPlayer.Initialise(_cSystemAddress, _cGuid, bIsHost); // Store network player instance s_mNetworkPlayers.Add(cNetworkPlayer.Guid.g, cNetworkPlayer); // Join notice Logger.Write("A player has joined. Instance id ({0}) System address ({1}) Guid ({2})", cNetworkPlayer.PlayerId, _cSystemAddress, _cGuid); // Notify event observers if (EventPlayerConnect != null) { EventPlayerConnect(cNetworkPlayer); } // Update server info, player count UpdateServerInfo(); // Tell player that he has been given the initial game state cNetworkPlayer.SetDownloadingInitialGameStateComplete(); }