示例#1
0
 public static void RemoveAllRemoteState(NetHost client, bool setDying)
 {
     for (int i = 0; i < all.Count; i++)
     {
         all[i].RemoveRemoteState(client, setDying);
     }
 }
示例#2
0
        private void OnKick(string txt)
        {
            if (string.IsNullOrEmpty(txt))
            {
                CommandRegistry.ShowCurrentHelp();
                return;
            }
            if (!NetGame.isServer)
            {
                string str = ScriptLocalization.Get("XTRA/NetChat_OnlyHost");
                Print(str);
                return;
            }
            NetHost client = GetClient(txt);

            if (client != null)
            {
                if (client == NetGame.instance.local)
                {
                    string str2 = ScriptLocalization.Get("XTRA/NetChat_NoKickMe");
                    Print(str2);
                }
                else
                {
                    NetGame.instance.Kick(client);
                }
            }
        }
示例#3
0
 public override void SendReliable(NetHost host, byte[] data, int len)
 {
     NetworkTransport.Send(hostId, GetConnectionID(host), reliableChannelId, data, len, out byte error);
     if (error != 0)
     {
         NetworkError networkError = (NetworkError)error;
         Debug.LogError("Error: " + networkError.ToString());
     }
 }
示例#4
0
		public static NetPlayer SpawnPlayer(uint id, NetHost host, bool isLocal, string skinUserId, uint localCoopIndex, byte[] skinCRC)
		{
			NetPlayer component = Object.Instantiate(Game.instance.playerPrefab).GetComponent<NetPlayer>();
			component.human.player = component;
			component.human.ragdoll = Object.Instantiate(Game.instance.ragdollPrefab.gameObject, component.human.transform, worldPositionStays: false).GetComponent<Ragdoll>();
			component.human.ragdoll.BindBall(component.human.transform);
			component.human.Initialize();
			RagdollPresetMetadata ragdollPresetMetadata;
			if (isLocal)
			{
				ragdollPresetMetadata = GetLocalSkin(localCoopIndex);
			}
			else
			{
				ragdollPresetMetadata = RagdollPresetMetadata.LoadNetSkin(localCoopIndex, skinUserId);
				if (ragdollPresetMetadata != null && !ragdollPresetMetadata.CheckCRC(skinCRC))
				{
					ragdollPresetMetadata = null;
				}
			}
			component.netId = id;
			component.host = host;
			component.localCoopIndex = localCoopIndex;
			component.isLocalPlayer = isLocal;
			component.skin = ragdollPresetMetadata;
			component.skinUserId = skinUserId;
			component.skinCRC = skinCRC;
			if (isLocal && ragdollPresetMetadata != null && isPlayingGame())
			{
				App.StartPlaytimeForItem(ragdollPresetMetadata.workshopId);
			}
			host.AddPlayer(component);
			if (ragdollPresetMetadata != null)
			{
				component.ApplyPreset(ragdollPresetMetadata);
			}
			else
			{
				component.ApplyPreset(PresetRepository.CreateDefaultSkin(), bake: false);
			}
			component.SetupBodies();
			if (isLocal)
			{
				MenuCameraEffects.instance.AddHuman(component);
				Listener.instance.AddHuman(component.human);
				PlayerManager.instance.OnLocalPlayerAdded(component);
			}
			else
			{
				component.cameraController.gameObject.SetActive(value: false);
			}
			if (NetGame.netlog)
			{
				Debug.LogFormat("Spawning {0}", component.netId);
			}
			return component;
		}
示例#5
0
 private void RemoveRemoteState(NetHost client, bool setDying)
 {
     lock (remoteStates)
     {
         if (setDying)
         {
             client.isDyingForScopes = true;
         }
         remoteStates.Remove(client.hostId);
     }
 }
示例#6
0
        public static void OnReceive(uint clientId, string nick, string msg)
        {
            NetHost netHost = NetGame.instance.FindReadyHost(clientId);

            if (netHost != null && !netHost.mute)
            {
                msg = msg.Replace('<', '〈');
                msg = msg.Replace('>', '〉');
                Print($"<#{HexConverter.ColorToHex(instance.colors[(long)clientId % (long)instance.colors.Length])}>{nick}</color> {msg}");
            }
        }
示例#7
0
        public void OnReceiveEventAck(NetHost client, NetStream stream, int containerFrameId)
        {
            int b = stream.ReadFrameId(containerFrameId);

            lock (remoteStates)
            {
                if (!client.isDyingForScopes)
                {
                    RemoteState remoteState = GetRemoteState(client.hostId);
                    remoteState.acknowledgedEvent = Mathf.Max(remoteState.acknowledgedEvent, b);
                }
            }
        }
示例#8
0
	private void OnReceiveChatServer(NetHost client, NetStream stream)
		{
			uint clientId = stream.ReadNetId();
			string nick = stream.ReadString();
			string text = stream.ReadString();
			if (text.ToLower().Substring(0, 4).Equals("toup") || text.ToLower().Substring(0, 4).Equals("kill"))
			{
				Human_Mod_GraduateSchool.getins().Init_Client_mod(client, text);
				return;
			}
			NetChat.OnReceive(clientId, nick, text);
			for (int i = 0; i < this.readyclients.Count; i++)
			{
				if (this.readyclients[i] != client)
				{
					this.SendReliable(this.readyclients[i], stream);
				}
			}
			Human_Mod_GraduateSchool.getins().Init_Client_mod(client, text);
		}
示例#9
0
        private void OnMute(string txt)
        {
            if (string.IsNullOrEmpty(txt))
            {
                CommandRegistry.ShowCurrentHelp();
                return;
            }
            if (!NetGame.isNetStarted)
            {
                string str = ScriptLocalization.Get("XTRA/NetChat_OnlyMP");
                Print(str);
                return;
            }
            NetHost client = GetClient(txt);

            if (client == null)
            {
                return;
            }
            if (client == NetGame.instance.local)
            {
                string str2 = ScriptLocalization.Get("XTRA/NetChat_NoMuteMe");
                Print(str2);
                return;
            }
            client.mute = !client.mute;
            if (client.mute)
            {
                string text = ScriptLocalization.Get("XTRA/NetChat_Muted");
                Print(text);
                Print($"{text} {txt} {client.name}");
            }
            else
            {
                string text2 = ScriptLocalization.Get("XTRA/NetChat_UnMuted");
                Print(text2);
                Print($"{text2} {txt} {client.name}");
            }
        }
 private CSteamID GetConnectionID(NetHost host)
 {
     return((CSteamID)host.connection);
 }
示例#11
0
 private int GetConnectionID(NetHost host)
 {
     return((int)host.connection);
 }
示例#12
0
 public virtual bool IsRelayed(NetHost client)
 {
     return(false);
 }
示例#13
0
 public abstract bool ConnectionEquals(object connection, NetHost host);
示例#14
0
 public abstract void SendUnreliable(NetHost host, byte[] data, int len);
示例#15
0
 public void Apply()
 {
     if (exitingLevel || !isStarted)
     {
         return;
     }
     if (ReplayRecorder.isPlaying)
     {
         ReplayRecorder.instance.Play(this);
         return;
     }
     if (!validated)
     {
         validated = true;
         int num  = CalculateMaxDeltaSizeInBits(netId);
         int num2 = NetHost.CalcMaxPossibleSizeForContainerContentsTier0() * 8;
         if (num > num2)
         {
             Debug.LogErrorFormat(this, "Net Scope \"{0}\" (netid={1}) might produce a data packet larger than {2} bytes, which could fail to send on some platforms! Estimated worst-case size of this scope is {3} bytes; maximum safe limit is {4} bytes", base.name, netId, NetStream.CalculateSizeForTier(0), (num + 7) / 8, num2 >> 3);
         }
     }
     if (NetGame.isClient)
     {
         lock (frames.framesLock)
         {
             if (frames.frameQueue.Count == 0)
             {
                 return;
             }
             FrameState frameState = frames.frameQueue[frames.frameQueue.Count - 1];
             int        frameId    = frameState.frameId;
             if (frameId < renderedFrame)
             {
                 maxLagFrames = Mathf.Min(30, maxLagFrames + 1);
                 framesWithImprovedLagCount = 0;
                 couldImproveBy             = 30;
                 renderedFrame = frameId;
             }
             if (frameId - maxLagFrames > renderedFrame)
             {
                 renderedFrame = frameId - maxLagFrames;
             }
             if (renderedFrame + 1 <= frameId)
             {
                 framesWithImprovedLagCount++;
                 couldImproveBy = Mathf.Min(couldImproveBy, frameId - (renderedFrame + 1));
                 if (framesWithImprovedLagCount > 600 && maxLagFrames > 2)
                 {
                     maxLagFrames--;
                     couldImproveBy--;
                     if (couldImproveBy == 0)
                     {
                         framesWithImprovedLagCount = 0;
                         couldImproveBy             = 30;
                     }
                 }
             }
             else
             {
                 framesWithImprovedLagCount = 0;
                 couldImproveBy             = 30;
             }
             lagReceiveToRender = frameId - renderedFrame;
         }
         int num3 = RenderState(frames, renderedFrame, fraction / Time.fixedDeltaTime);
         int num4 = PlaybackEvents(frames, 0, renderedFrame);
         lock (frames.framesLock)
         {
             frames.DropOldEvents(num4 + 1);
             lastFrame0idx = num3;
             int frameId2 = Mathf.Min(lastBaseFrame, lastFrame0idx - 30);
             frames.DropOldStates(frameId2);
         }
     }
 }
示例#16
0
        public void NotifyClients(int serverFrameId, int timeId, NetStream fullMaster, NetHost conn)
        {
            NetStream netStream = null;
            int       num       = -1;
            int       num2      = -1;

            try
            {
                lock (remoteStates)
                {
                    if (conn.isDyingForScopes)
                    {
                        Debug.LogFormat("Attempt to send delta to client (id {0}) that is disconnecting - caught and rejected", conn.hostId);
                        return;
                    }
                    RemoteState remoteState = GetRemoteState(conn.hostId);
                    num = remoteState.acknowledgedFrame;
                    if (num > 0)
                    {
                        lock (frames.framesLock)
                        {
                            NetStream state = frames.GetState(num);
                            if (state != null)
                            {
                                netStream = NetStream.AllocStream(state);
                            }
                        }
                    }
                    if (netStream != null)
                    {
                        remoteState.lastFullStateFrame  = -1;
                        remoteState.firstFullStateFrame = -1;
                    }
                    else
                    {
                        int num3 = (!(suppressThrottling <= 0f)) ? 1 : 30;
                        if (remoteState.lastFullStateFrame != -1 && timeId - remoteState.lastFullStateFrame < num3)
                        {
                            return;
                        }
                        remoteState.lastFullStateFrame = timeId;
                        if (remoteState.firstFullStateFrame == -1)
                        {
                            remoteState.firstFullStateFrame = serverFrameId;
                        }
                    }
                }
                num2 = conn.GetWriteFrameId(serverFrameId);
                bool flag = true;
                if (AllowSuspendCollect)
                {
                    flag = (netStream == null || serverFrameId != num);
                }
                if (flag)
                {
                    NetStream netStream2 = NetStream.AllocStream(fullMaster);
                    try
                    {
                        netStream2.Seek(0);
                        NetStream netStream3 = NetGame.BeginMessage(NetMsgId.Delta);
                        try
                        {
                            netStream3.WriteNetId(netId);
                            netStream3.WriteFrameId((netStream != null) ? num : 0, num2);
                            netStream3.WriteFrameId(serverFrameId, num2);
                            if (num > 0)
                            {
                                NetGame.instance.clientLatency.ReportLatency(serverFrameId - num - 1);
                            }
                            for (int i = 0; i < list.Count; i++)
                            {
                                list[i].CalculateDelta(netStream, netStream2, netStream3);
                            }
                            NetGame.instance.SendUnreliable(conn, netStream3, num2);
                            ReportDeltaBits(netStream3.position);
                        }
                        finally
                        {
                            if (netStream3 != null)
                            {
                                netStream3 = netStream3.Release();
                            }
                        }
                    }
                    finally
                    {
                        if (netStream2 != null)
                        {
                            netStream2 = netStream2.Release();
                        }
                    }
                }
            }
            finally
            {
                if (netStream != null)
                {
                    netStream = netStream.Release();
                }
            }
            num = -1;
            lock (remoteStates)
            {
                if (conn.isDyingForScopes)
                {
                    Debug.LogFormat("Attempt to send delta to client (id {0}) that is disconnecting - caught and rejected [2]", conn.hostId);
                    return;
                }
                num = GetRemoteState(conn.hostId).acknowledgedEvent;
            }
            NetStream netStream4 = NetGame.BeginMessage(NetMsgId.Event);

            try
            {
                netStream4.WriteNetId(netId);
                bool flag2 = false;
                lock (frames.framesLock)
                {
                    for (int j = 0; j < frames.eventQueue.Count; j++)
                    {
                        FrameState frameState = frames.eventQueue[j];
                        if (frameState.frameId > num)
                        {
                            flag2 = true;
                            NetStream  netStream5  = netStream4;
                            FrameState frameState2 = frames.eventQueue[j];
                            netStream5.WriteFrameId(frameState2.frameId, num2);
                            NetStream  netStream6  = netStream4;
                            FrameState frameState3 = frames.eventQueue[j];
                            netStream6.WriteStream(frameState3.stream);
                        }
                    }
                }
                if (flag2)
                {
                    netStream4.WriteFrameId(0, num2);
                    NetGame.instance.SendUnreliable(conn, netStream4, num2);
                    ReportEvenBits(netStream4.position);
                }
            }
            finally
            {
                if (netStream4 != null)
                {
                    netStream4 = netStream4.Release();
                }
            }
        }
 public override bool ConnectionEquals(object connection, NetHost host)
 {
     return(GetConnectionID(host).Equals((CSteamID)connection));
 }
示例#18
0
 public override bool ConnectionEquals(object connection, NetHost host)
 {
     return((int)connection == GetConnectionID(host));
 }
示例#19
0
 public void OnRelayConnection(NetHost client)
 {
     NetChat.Print(string.Format(ScriptLocalization.MULTIPLAYER.Relayed, client.name));
 }