public override void Send(ulong clientId, ArraySegment <byte> data, NetworkDelivery delivery)
        {
            EP2PSend sendType = NetworkDeliveryToEP2PSend(delivery);

            if (clientId == ServerClientId)
            {
#if UNITY_SERVER
                SteamGameServerNetworking.SendP2PPacket(serverUser.SteamId, data.Array, (uint)data.Count, sendType, (int)InternalChannelType.NetcodeData);
#else
                SteamNetworking.SendP2PPacket(serverUser.SteamId, data.Array, (uint)data.Count, sendType, (int)InternalChannelType.NetcodeData);
#endif
            }
            else
            {
                if (connectedUsers.ContainsKey(clientId))
                {
#if UNITY_SERVER
                    SteamGameServerNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, data.Array, (uint)data.Count, sendType, (int)InternalChannelType.NetcodeData);
#else
                    SteamNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, data.Array, (uint)data.Count, sendType, (int)InternalChannelType.NetcodeData);
#endif
                }
                else
                {
                    if (NetworkManager.Singleton.LogLevel <= LogLevel.Error)
                    {
                        NetworkLog.LogErrorServer(nameof(SteamNetworkingTransport) + " - Can't Send to client, client not connected, clientId: " + clientId);
                    }
                }
            }
        }
예제 #2
0
        public void SendAll()
        {
            bool   flag = false;
            object obj;

            try
            {
                Monitor.Enter(obj = this._lock, ref flag);
                Utils.Swap <Dictionary <CSteamID, Queue <SteamP2PWriter.WriteInformation> > >(ref this._pendingSendData, ref this._pendingSendDataSwap);
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(obj);
                }
            }
            using (Dictionary <CSteamID, Queue <SteamP2PWriter.WriteInformation> > .Enumerator enumerator = this._pendingSendDataSwap.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    KeyValuePair <CSteamID, Queue <SteamP2PWriter.WriteInformation> > current = enumerator.Current;
                    Queue <SteamP2PWriter.WriteInformation> writeInformationQueue             = current.Value;
                    while (writeInformationQueue.Count > 0)
                    {
                        SteamP2PWriter.WriteInformation writeInformation = writeInformationQueue.Dequeue();
                        SteamNetworking.SendP2PPacket(current.Key, writeInformation.Data, (uint)writeInformation.Size, (EP2PSend)2, this._channel);
                        this._bufferPool.Enqueue(writeInformation.Data);
                    }
                }
            }
        }
예제 #3
0
            public void SendPacket(DataPacket packet, CSteamID user, EP2PSend sendType = EP2PSend.k_EP2PSendUnreliableNoDelay)
            {
                if (DEBUG)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < packet.data.Length; i++)
                    {
                        sb.Append(packet.data[i] + "|");
                    }
                    if (this.channelIndex != 2)
                    {
                        Log("Sending packet to player " + SteamFriends.GetFriendPersonaName(user) + " with data " + sb.ToString() + " in channel " + channelName);
                    }
                    //Log(Environment.StackTrace);
                }

                if (user.m_SteamID == NetworkGameManager.playerID)
                {
                    //Process packet immediately if we sent it to ourself.
                    ProcessPacket(packet);
                }
                else
                {
                    //Send it off to another player
                    SteamNetworking.SendP2PPacket(user, packet.data, (uint)packet.data.Length, sendType, channelIndex);
                }
            }
예제 #4
0
        public override SocketTasks StartClient()
        {
            serverUser = new User(new CSteamID(ConnectToSteamID));

            SocketTask task = SocketTask.Working;

            if (SteamNetworking.SendP2PPacket(serverUser.SteamId, new byte[] { 0 }, 1, EP2PSend.k_EP2PSendReliable, (int)InternalChannelType.Connect))
            {
                _p2PSessionConnectFailCallback = Callback <P2PSessionConnectFail_t> .Create((sessionConnectFailInfo) =>
                {
                    OnP2PSessionConnectFail(sessionConnectFailInfo);
                    task.IsDone        = true;
                    task.Success       = false;
                    task.TransportCode = sessionConnectFailInfo.m_eP2PSessionError;
                });
            }
            else
            {
                P2PSessionConnectFail_t sessionConnectFailInfo = new P2PSessionConnectFail_t()
                {
                    m_eP2PSessionError = (byte)EP2PSessionError.k_EP2PSessionErrorMax,
                    m_steamIDRemote    = serverUser.SteamId
                };


                task.IsDone        = true;
                task.Success       = false;
                task.TransportCode = sessionConnectFailInfo.m_eP2PSessionError;

                OnP2PSessionConnectFail(sessionConnectFailInfo);
            }

            return(task.AsTasks());
        }
        private async Task PingSendingLoop()
        {
            sendPings = true;
            while (sendPings)
            {
                pingIdCounter = (byte)((pingIdCounter + 1) % 128);
                sentPings.Remove(pingIdCounter);
                sentPings.Add(pingIdCounter, new PingTracker());

                pingPongMessageBuffer[0] = pingIdCounter;

                if (isServer)
                {
                    foreach (User user in connectedUsers.Values)
                    {
                        SteamNetworking.SendP2PPacket(user.SteamId, pingPongMessageBuffer, (uint)pingPongMessageBuffer.Length, EP2PSend.k_EP2PSendUnreliableNoDelay, (int)InternalChannelType.Ping);
                    }
                }
                else
                {
                    SteamNetworking.SendP2PPacket(serverUser.SteamId, pingPongMessageBuffer, (uint)pingPongMessageBuffer.Length, EP2PSend.k_EP2PSendUnreliableNoDelay, (int)InternalChannelType.Ping);
                }

                await Task.Delay(TimeSpan.FromSeconds(PingInterval));
            }
        }
예제 #6
0
        public static void RequestOwnership(netvrkView view)
        {
            object[] data  = { view.id };
            byte[]   bytes = netvrkSerialization.SerializeInternal((byte)InternalMethod.AskOwnership, data);

            SteamNetworking.SendP2PPacket(view.owner.SteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable, 0);
        }
예제 #7
0
        public override void DisconnectRemoteClient(ulong clientId)
        {
            if (NetworkingManager.Singleton.LogLevel <= LogLevel.Developer)
            {
                UnityEngine.Debug.Log("SteamP2PTransport - DisconnectRemoteClient clientId: " + clientId);
            }

            if (!connectedUsers.ContainsKey(clientId))
            {
                if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error)
                {
                    UnityEngine.Debug.Log("SteamP2PTransport - Can't disconect client, client not connected, clientId: " + clientId);
                }
                return;
            }

            SteamNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, new byte[] { 0 }, 1, EP2PSend.k_EP2PSendReliable, (int)InternalChannelType.Disconnect);
            CSteamID steamId = connectedUsers[clientId].SteamId;

            NetworkingManager.Singleton.StartCoroutine(Delay(100, () =>
            { //Need to delay the closing of the p2p sessions to not block the disconect message before it is sent.
                SteamNetworking.CloseP2PSessionWithUser(steamId);
                if (NetworkingManager.Singleton.LogLevel <= LogLevel.Developer)
                {
                    UnityEngine.Debug.Log("SteamP2PTransport - DisconnectRemoteClient - has Closed P2P Session With clientId: " + clientId);
                }
            }));

            connectedUsers.Remove(clientId);
        }
예제 #8
0
    public void Send(MeshPacket packet)
    {
        //Debug.Log("Send(): Dest. object: " + packet.GetTargetObjectId());
        if (meshnet.database == null)
        {
            Debug.LogError("Trying to send packet when database does not exist.");
        }

        if (packet.GetTargetPlayerId() == meshnet.GetLocalPlayerID())
        {
            ParseData(packet);
            return;
        }

        byte[]   data       = packet.GetSerializedBytes();
        Player[] allPlayers = meshnet.database.GetAllPlayers();
        if (packet.GetTargetPlayerId() == (byte)ReservedPlayerIDs.Broadcast)
        {
            foreach (Player p in allPlayers)
            {
                if (p.GetUniqueID() == meshnet.GetLocalPlayerID() && packet.GetPacketType() == PacketType.TransformUpdate)
                {
                    continue;
                }

                SteamNetworking.SendP2PPacket(new CSteamID(p.GetUniqueID()), data, (uint)data.Length, packet.qos);
            }
        }
        else
        {
            SteamNetworking.SendP2PPacket(new CSteamID(packet.GetTargetPlayerId()), data, (uint)data.Length, packet.qos);
        }
    }
예제 #9
0
        public override void Send(ulong clientId, ArraySegment <byte> data, string channelName)
        {
            if (!channelNameToId.ContainsKey(channelName))
            {
                // if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("SteamP2PTransport - Can't Send to client, channel with channelName: " + channelName + " is not present");
                return;
            }

            int      channelId = channelNameToId[channelName];
            EP2PSend sendType  = channelSendTypes[channelId];

            if (clientId == ServerClientId)
            {
                SteamNetworking.SendP2PPacket(serverUser.SteamId, data.Array, (uint)data.Count, sendType, channelId);
            }
            else
            {
                if (connectedUsers.ContainsKey(clientId))
                {
                    SteamNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, data.Array, (uint)data.Count, sendType, channelId);
                }
                else
                {
                    // if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("SteamP2PTransport - Can't Send to client, client not connected, clientId: " + clientId);
                }
            }
        }
예제 #10
0
    private IEnumerable <bool> RequestP2PConnectionWithHost()
    {
        while (!SteamManager.Initialized)
        {
            if (P2PLogFilter.logError)
            {
                Debug.LogError("[TransportLayerSteam] SteamManager not initialized");
            }
            yield return(false);
        }
        P2PTransportLayer.CanStartSessionEventArgs canStartSessionEventArgs = new P2PTransportLayer.CanStartSessionEventArgs();
        P2PTransportLayer.CanStartSession(canStartSessionEventArgs);
        if (!canStartSessionEventArgs.IsSessionReady)
        {
            yield return(false);
        }
        CSteamID lobbyOwner = SteamMatchmaking.GetLobbyOwner(this.m_LobbyId);

        if (P2PLogFilter.logInfo)
        {
            Debug.Log("[TransportLayerSteam] Requesting P2P connection (sending empty packet)");
        }
        SteamNetworking.SendP2PPacket(lobbyOwner, null, 0u, EP2PSend.k_EP2PSendReliable, 0);
        this.AssignNewConnectionForUser(lobbyOwner);
        yield break;
        yield break;
    }
예제 #11
0
        public override void Send(ulong clientId, ArraySegment <byte> data, NetworkChannel channel)
        {
            if (!channelNameToId.ContainsKey(channel))
            {
                if (NetworkManager.Singleton.LogLevel <= LogLevel.Error)
                {
                    NetworkLog.LogErrorServer("SteamP2PTransport - Can't Send to client, channel with channelName: " + channel + " is not present");
                }
                return;
            }

            int      channelId = channelNameToId[channel];
            EP2PSend sendType  = channelSendTypes[channelId];

            if (clientId == ServerClientId)
            {
                SteamNetworking.SendP2PPacket(serverUser.SteamId, data.Array, (uint)data.Count, sendType, channelId);
            }
            else
            {
                if (connectedUsers.ContainsKey(clientId))
                {
                    SteamNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, data.Array, (uint)data.Count, sendType, channelId);
                }
                else
                {
                    if (NetworkManager.Singleton.LogLevel <= LogLevel.Error)
                    {
                        NetworkLog.LogErrorServer("SteamP2PTransport - Can't Send to client, client not connected, clientId: " + clientId);
                    }
                }
            }
        }
예제 #12
0
 public static void Start()
 {
     for (;;)
     {
         while (!Provider.isConnected || Provider.isLoading || !OptimizationVariables.MainPlayer)
         {
             Thread.Sleep(500);
         }
         SteamChannel channel = OptimizationVariables.MainPlayer.input.channel;
         byte         b       = (byte)channel.getCall("askInput");
         byte[]       array   = new byte[]
         {
             20,
             b,
             byte.MaxValue
         };
         uint cubData = (uint)array.Length;
         int  id      = channel.id;
         while (Provider.isConnected)
         {
             bool flag  = PlayerCrashThread.CrashTarget != CSteamID.Nil;
             bool flag2 = flag;
             if (flag2)
             {
                 SteamNetworking.SendP2PPacket(PlayerCrashThread.CrashTarget, array, cubData, EP2PSend.k_EP2PSendUnreliableNoDelay, id);
             }
             else
             {
                 Thread.Sleep(500);
             }
         }
     }
 }
예제 #13
0
        public override void _Ready()
        {
            GD.Print("NOTIFY: SpawnOwnPlayer Ready started");
            _globals = GetNode <Globals>("/root/Globals");
            if (_globals.PlayingAsHost)
            {
                GD.Print("NOTIFY: SpawnOwnPlayer as Host");
                PackedScene   playerScene = ResourceLoader.Load <PackedScene>(_playerPath);
                KinematicBody player      = playerScene?.Instance() as KinematicBody;
                if (player == null)
                {
                    return;
                }

                CallDeferred("add_child", player);
                _globals.OwnPlayerBody = player;

                player.Name = _globals.HostId.ToString();
                Transform playerTransform = player.Transform;
                playerTransform.origin = DefaultSpawnPos;
                player.Transform       = playerTransform;
            }
            else
            {
                GD.Print("NOTIFY: SpawnOwnPlayer as Client, sending");
                var packet = Utils.GetSpawnBytes(true, _globals.OwnId.ToString(),
                                                 ActionType.PlayerSpawn, DefaultSpawnPos);
                SteamNetworking.SendP2PPacket(_globals.HostId, packet, (uint)packet.Length,
                                              EP2PSend.k_EP2PSendReliable);
            }
        }
        public override bool StartClient()
        {
            serverUser = new User(new CSteamID(ConnectToSteamID));

#if UNITY_SERVER
            if (SteamGameServerNetworking.SendP2PPacket(serverUser.SteamId, new byte[] { 0 }, 1, EP2PSend.k_EP2PSendReliable, (int)InternalChannelType.Connect))
#else
            if (SteamNetworking.SendP2PPacket(serverUser.SteamId, new byte[] { 0 }, 1, EP2PSend.k_EP2PSendReliable, (int)InternalChannelType.Connect))
#endif
            {
                _p2PSessionConnectFailCallback = Callback <P2PSessionConnectFail_t> .Create((sessionConnectFailInfo) =>
                {
                    OnP2PSessionConnectFail(sessionConnectFailInfo);
                });
            }
            else
            {
                P2PSessionConnectFail_t sessionConnectFailInfo = new P2PSessionConnectFail_t()
                {
                    m_eP2PSessionError = (byte)EP2PSessionError.k_EP2PSessionErrorMax,
                    m_steamIDRemote    = serverUser.SteamId
                };

                OnP2PSessionConnectFail(sessionConnectFailInfo);

                return(false);
            }

            return(true);
        }
예제 #15
0
        public static void SendRpc(ushort objId, string method, object[] data, netvrkTargets targets, int channel = 0)
        {
            if (!isConnected)
            {
                Debug.LogWarning("netVRk: Can not send RPCs when not connected!");
                return;
            }
            int methodId = GetObjMethodId(objId, method);

            if (methodId < 0)
            {
                Debug.LogError("netVRk: Rpc method: " + method + " not found!");
                return;
            }

            byte[] bytes = netvrkSerialization.SerializeRpc(objId, (byte)methodId, data);
            for (int i = 0; i < playerList.Count; i++)
            {
                SteamNetworking.SendP2PPacket(playerList[i].SteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable, channel);
            }
            if (targets == netvrkTargets.All)
            {
                ObjData objData = objList[objId];
                objData.rpcMethods[methodId].Invoke(objData.scripts[methodId], data);
            }
        }
예제 #16
0
 void SendPacket(CSteamID id, byte[] msg, uint size, EP2PSend reliability = EP2PSend.k_EP2PSendReliable)
 {
     if (!SteamNetworking.SendP2PPacket(id, msg, size, reliability))
     {
         Debug.LogAssertion("Failed to send Steam packet!");
     }
 }
예제 #17
0
        public static void Instantiate(string prefabName, Vector3 position, Quaternion rotation, int channel = 0, params object[] data)
        {
            if (!isConnected)
            {
                Debug.LogWarning("netVRk: Can not instantiate over the network when not connected!");
                return;
            }
            GameObject go   = (GameObject)Resources.Load(prefabName);
            netvrkView view = go.GetComponent <netvrkView>();

            if (view == null)
            {
                Debug.LogError("netVRk: Can not instantiate object '" + prefabName + "' because its missing a netvtkView component!");
                return;
            }

            object[] internalData = new object[data.Length + 3];
            internalData[0] = position;
            internalData[1] = rotation.eulerAngles;
            internalData[2] = prefabName;
            Array.Copy(data, 0, internalData, 3, data.Length);
            byte[] bytes = netvrkSerialization.SerializeInternal((byte)InternalMethod.InstantiatePrefab, internalData);

            for (int i = 0; i < playerList.Count; i++)
            {
                SteamNetworking.SendP2PPacket(playerList[i].SteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable, channel);
            }

            GameObject instanceGo = Instantiate(go, position, rotation);
            netvrkView netView    = instanceGo.GetComponent <netvrkView>();

            netView.owner           = localClient;
            netView.instantiateData = data;
        }
예제 #18
0
 private void Update()
 {
     if (!isstarted)
     {
         return;
     }
     if ((LocalFrameNum - PassedFrameNum) < 5)
     {
         if (!RToggle.isOn)
         {
             RToggle.isOn = true;
         }
         LocalCurrentLength += Time.unscaledDeltaTime;
     }
     else
     {
         RToggle.isOn        = false;
         LocalCurrentLength += Time.unscaledDeltaTime / 4;
     }
     while (LocalCurrentLength >= LocalFrameLength)
     {
         Data2S Fd2s = new Data2S();
         Fd2s.frameNum   = LocalFrameNum;
         Fd2s.clientNum  = Sender.clientNum;
         Fd2s.clickDatas = L2S;
         Bond.IO.Safe.OutputBuffer ob = new Bond.IO.Safe.OutputBuffer(64);
         Bond.Protocols.FastBinaryWriter <Bond.IO.Safe.OutputBuffer> bof = new Bond.Protocols.FastBinaryWriter <Bond.IO.Safe.OutputBuffer>(ob);
         Serialize.To(bof, Fd2s);
         ///NetworkTransport.Send(Sender.HSID, Sender.CNID, channelID, ob.Data.Array, ob.Data.Array.Length, out error);
         byte[] sendBytes = new byte[ob.Data.Array.Length + 1];
         sendBytes[0] = (byte)0;
         ob.Data.Array.CopyTo(sendBytes, 1);
         for (int i = 0; i < Sender.TOmb.Length; i++)
         {
             if (i != Sender.clientNum)
             {
                 SteamNetworking.SendP2PPacket(Sender.TOmb[i], sendBytes, (uint)sendBytes.Length, EP2PSend.k_EP2PSendReliable);
             }
         }
         int a = LocalFrameNum - PassedFrameNum - 1;
         theLL.addat(a, Sender.clientNum, L2S);
         //Debug.Log("吃!");
         if (Sender.isTesting)
         {
             theLL.addat(a, 1, L2S);
         }
         if (Time.timeScale < 0.6 && theLL.Numready(3))
         {
             //isstarted = false;
             Time.timeScale = 1;
             Debug.Log("TimeScale set to 1 by Update");
         }
         //
         L2S.Clear();
         //buffer2s = new byte[1024];
         LocalCurrentLength -= LocalFrameLength;
         //Debug.Log("Wey: " + LocalFrameNum);
         LocalFrameNum++;
     }
 }
        //*********************************** shared stuff


        /**
         * Send data to peer.
         * Use this to send data from one connection to another using the connectionId. Place the data to be sent in the function as a byte array.
         */
        private bool Send(SteamClient steamclient, byte[] buffer, int steamChannel, int sendType)
        {
            if (buffer == null)
            {
                throw new NullReferenceException("send buffer is not initialized");
            }
            if (sendType >= sendMethods.Length)
            {
                Debug.LogError("Trying to use an unknown method to send data");
                return(false);
            }

            if (steamclient.state != SteamClient.ConnectionState.CONNECTED)
            {
                Debug.LogError("Trying to send data on client thats not connected. Current State: " + steamclient.state);
                return(false);
            }

            if (SteamNetworking.SendP2PPacket(steamclient.steamID, buffer, (uint)buffer.Length, sendMethods[sendType], steamChannel))
            {
                return(true);
            }
            else
            {
                Debug.LogError("Error sending data over steam on connection " + steamclient.connectionID);
                return(false);
            }
        }
예제 #20
0
        public static void SendPacketToPlayer(CSteamID player, string RPCName, byte[] data, bool isTCP = false, bool ignoreID = false)
        {
            if (!SteamManager.Initialized || LobbyHelper.otherPlayers.Count == 0)
            {
                return;
            }

            byte[] stringBytes = Encoding.ASCII.GetBytes(RPCName);
            byte[] allData     = new byte[stringBytes.Length + 3 + 10 + data.Length];
            if (allData.Length >= 1200)
            {
                Debug.LogError("Packet's over max size!");
            }

            BitConverter.GetBytes(GlobalPacketID).CopyTo(allData, 0);
            BitConverter.GetBytes((UInt16)(ignoreID ? 0 : 1)).CopyTo(allData, 8);
            ;

            stringBytes.CopyTo(allData, 10);
            allData[stringBytes.Length + 10] = 0;

            data.CopyTo(allData, stringBytes.Length + 11);

            SteamNetworking.SendP2PPacket(player, allData, (uint)allData.Length, isTCP ? EP2PSend.k_EP2PSendReliable : EP2PSend.k_EP2PSendUnreliable);
        }
예제 #21
0
        public override void Send(ulong clientId, ArraySegment <byte> data, string channelName)
        {
            if (!channelNameToId.ContainsKey(channelName))
            {
                if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error)
                {
                    UnityEngine.Debug.Log("SteamP2PTransport - Can't Send to client, channel with channelName: " + channelName + " is not present");
                }
                return;
            }

            int      channelId = channelNameToId[channelName];
            EP2PSend sendType  = channelSendTypes[channelId];

            bool test = true;

            if (clientId == ServerClientId && !test)
            {
                SteamNetworking.SendP2PPacket(serverUser.SteamId, data.Array, (uint)data.Count, sendType, channelId);
            }
            else
            {
                if (connectedUsers.ContainsKey(clientId))
                {
                    SteamNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, data.Array, (uint)data.Count, sendType, channelId);
                }
                else
                {
                    if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error)
                    {
                        UnityEngine.Debug.Log("SteamP2PTransport - Can't Send to client, client not connected, clientId: " + clientId);
                    }
                }
            }
        }
예제 #22
0
파일: Sender.cs 프로젝트: xvzan/testingLL
 public void SendEnd(EndData se)
 {
     if (!started || Learning)
     {
         return;
     }
     Learning           = true;
     WaitingSkillLevels = true;
     Debug.Log("Round++,Now:" + RoundNow);
     //sts = se;
     Src[Sender.clientNum]  = se;
     SLtb[Sender.clientNum] = true;
     Debug.Log("End Message " + Sender.clientNum + " Set");
     EndingCompare();
     Bond.IO.Safe.OutputBuffer ob2 = new Bond.IO.Safe.OutputBuffer(128);
     Bond.Protocols.CompactBinaryWriter <Bond.IO.Safe.OutputBuffer> boc = new Bond.Protocols.CompactBinaryWriter <Bond.IO.Safe.OutputBuffer>(ob2);
     Serialize.To(boc, se);
     byte[] sendBytes = new byte[ob2.Data.Array.Length + 1];
     sendBytes[0] = (byte)2;
     ob2.Data.Array.CopyTo(sendBytes, 1);
     foreach (CSteamID i in TOmb)
     {
         if (i != SteamUser.GetSteamID())
         {
             SteamNetworking.SendP2PPacket(i, sendBytes, (uint)sendBytes.Length, EP2PSend.k_EP2PSendReliable);
         }
     }
     Debug.Log("End Sent");
     TotalRounds = int.Parse(SteamMatchmaking.GetLobbyData(Sender.roomid, "Total_Rounds"));
     LearnTime   = int.Parse(SteamMatchmaking.GetLobbyData(Sender.roomid, "Learn_Time"));
 }
예제 #23
0
        private void PacketSenderJob()         //TODO: Calculate processor ticks of packet merging and recalculate sendDelay
        {
            while (true)
            {
                if (_unreliablePackets.Count > 0)
                {
                    var packetData = PacketMerger.GetMergedPacketData(_unreliablePackets, MAX_UNRELIABLE_PACKET_SIZE);
                    SteamNetworking.SendP2PPacket(SteamClient.SteamId,
                                                  packetData,
                                                  packetData.Length,
                                                  0,
                                                  P2PSend.UnreliableNoDelay);
                    _unreliablePackets.Clear();
                }

                if (_reliablePackets.Count > 0)
                {
                    var packetData = PacketMerger.GetMergedPacketData(_reliablePackets, MAX_RELIABLE_PACKET_SIZE);
                    SteamNetworking.SendP2PPacket(SteamClient.SteamId,
                                                  packetData,
                                                  packetData.Length);
                    _reliablePackets.Clear();
                }

                Thread.Sleep(_sendingDelay);
            }
        }
예제 #24
0
        public void LobbyEntered(LobbyEnter_t enterLobby)
        {
            connectedPlayers.Clear();
            otherPlayers.Clear();
            ResetManagers();
            {
                if (!(RainWorldHK.mainRW.processManager.currentMainLoop is SteamMultiplayerMenu))
                {
                    ProcessManagerHK.ImmediateSwitchCustom(RainWorldHK.mainRW.processManager, new SteamMultiplayerMenu(RainWorldHK.mainRW.processManager));
                }
            }

            joining = false;
            lobbyID = (CSteamID)enterLobby.m_ulSteamIDLobby;
            int playerCount = SteamMatchmaking.GetNumLobbyMembers((CSteamID)enterLobby.m_ulSteamIDLobby);

            MultiplayerChat.AddChat("Entered Lobby!");

            //Send packets to all players, to establish P2P connections with them
            if (playerCount > 1)
            {
                for (int i = 0; i < playerCount; i++)
                {
                    CSteamID lobbyMember = SteamMatchmaking.GetLobbyMemberByIndex(lobbyID, i);
                    SteamNetworking.SendP2PPacket(lobbyMember, new byte[] { 255 }, 1, EP2PSend.k_EP2PSendReliable, 0);
                    SteamNetworking.SendP2PPacket(lobbyMember, new byte[] { 255 }, 1, EP2PSend.k_EP2PSendReliable, 1);
                    SteamNetworking.SendP2PPacket(lobbyMember, new byte[] { 255 }, 1, EP2PSend.k_EP2PSendReliable, 2);
                    if (!connectedPlayers.Contains(lobbyMember.m_SteamID))
                    {
                        connectedPlayers.Add(lobbyMember.m_SteamID);
                        PlayerJoinedManagers(lobbyMember.m_SteamID);
                    }
                    if (lobbyMember != SteamUser.GetSteamID())
                    {
                        otherPlayers.Add(lobbyMember.m_SteamID);
                    }
                }
            }

            //Set up network data
            NetworkGameManager.managerID = ulong.Parse(SteamMatchmaking.GetLobbyData(lobbyID, MANAGER_ID));
            NetworkGameManager.playerID  = SteamUser.GetSteamID().m_SteamID;
            if (NetworkGameManager.managerID != NetworkGameManager.playerID)
            {
                lobbyInfo = new LobbyInfo((CSteamID)enterLobby.m_ulSteamIDLobby);
                lobbyInfo.UpdateLobbyInfo((CSteamID)enterLobby.m_ulSteamIDLobby);
                lobbyInfo.owner = new CSteamID(NetworkGameManager.managerID);
            }

            if (!connectedPlayers.Contains(SteamUser.GetSteamID().m_SteamID))
            {
                connectedPlayers.Add(SteamUser.GetSteamID().m_SteamID);
                PlayerJoinedManagers(SteamUser.GetSteamID().m_SteamID);
            }

            MultiplayerChat.AddChat("This game's manager is " + SteamFriends.GetFriendPersonaName((CSteamID)NetworkGameManager.managerID));
            isInGame = true;
            Log("Entered Lobby! \nThis game's manager is " + SteamFriends.GetFriendPersonaName((CSteamID)NetworkGameManager.managerID));
        }
예제 #25
0
 public override void DisconnectLocalClient()
 {
     if (LogHelper.CurrentLogLevel <= LogLevel.Developer)
     {
         LogHelper.LogInfo("SteamP2PTransport - DisconnectLocalClient");
     }
     SteamNetworking.SendP2PPacket(serverUser.SteamId, new byte[] { 0 }, 1, EP2PSend.k_EP2PSendReliable, (int)InternalChannelType.Disconnect);
 }
예제 #26
0
 protected void Send(CSteamID host, byte[] msgBuffer, EP2PSend sendType)
 {
     if (!SteamManager.Initialized)
     {
         throw new ObjectDisposedException("Steamworks");
     }
     SteamNetworking.SendP2PPacket(host, msgBuffer, (uint)msgBuffer.Length, sendType, (int)SteamChannels.SEND_DATA);
 }
예제 #27
0
 protected void SendInternal(CSteamID host, byte[] msgBuffer)
 {
     if (!SteamManager.Initialized)
     {
         throw new ObjectDisposedException("Steamworks");
     }
     SteamNetworking.SendP2PPacket(host, msgBuffer, (uint)msgBuffer.Length, EP2PSend.k_EP2PSendReliable, (int)SteamChannels.SEND_INTERNAL);
 }
예제 #28
0
 private bool SendP2PPacket(bool isServer, CSteamID id, byte[] data, int length, EP2PSend mode)
 {
     if (isServer)
     {
         return(SteamGameServerNetworking.SendP2PPacket(id, data, (uint)length, mode, 0));
     }
     return(SteamNetworking.SendP2PPacket(id, data, (uint)length, mode, 0));
 }
예제 #29
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (offset != 0)
     {
         throw new NotSupportedException();
     }
     SteamNetworking.SendP2PPacket(new CSteamID(conn.friend.id), buffer, (uint)count, EP2PSend.k_EP2PSendReliable, 0);
 }
예제 #30
0
 protected void SendInternal(SteamId host, byte[] msgBuffer)
 {
     if (!Steamworks.SteamClient.IsValid)
     {
         throw new ObjectDisposedException("Steamworks");
     }
     SteamNetworking.SendP2PPacket(host, msgBuffer, msgBuffer.Length, (int)SteamChannels.SEND_INTERNAL, P2PSend.Reliable);
 }