示例#1
0
            public static bool Prefix(InnerNetClient __instance,
                                      [HarmonyArgument(0)] MessageReader reader)
            {
                // If i am host, respond to handshake
                if (__instance.AmHost && reader.BytesRemaining > 3)
                {
                    var handshakeReader = MessageReader.Get(reader).ReadMessageAsNewBuffer();
                    if (handshakeReader.Tag == TOU_ROOT_HANDSHAKE_TAG)
                    {
                        PluginSingleton <TownOfUs> .Instance.Log.LogMessage($"InnerNetClient.HandleMessage.Prefix - Host recieved TOU handshake");

                        var clientId   = handshakeReader.ReadInt32();
                        var touVersion = handshakeReader.ReadString();

                        // List<int> HandshakedClients - exists to disconnect legacy clients that don't send handshake
                        PluginSingleton <TownOfUs> .Instance.Log.LogMessage($"InnerNetClient.HandleMessage.Prefix - Adding {clientId} with TOU version {touVersion} to List<int>HandshakedClients");

                        HandshakedClients.Add(clientId);

                        if (!TownOfUs.GetVersion().Equals(touVersion))
                        {
                            PluginSingleton <TownOfUs> .Instance.Log.LogMessage($"InnerNetClient.HandleMessage.Prefix - ClientId {clientId} has mismatched TOU version {touVersion}. (Ours is {TownOfUs.GetVersion()})");

                            __instance.SendCustomDisconnect(clientId);
                        }

                        return(false);
                    }
                }

                return(true);
            }
示例#2
0
        private static void SendCustomDisconnect(this InnerNetClient innerNetClient, int clientId)
        {
            var messageWriter = MessageWriter.Get(SendOption.Reliable);

            messageWriter.StartMessage(11);
            messageWriter.Write(innerNetClient.GameId);
            messageWriter.WritePacked(clientId);
            messageWriter.Write(false);
            messageWriter.Write(8);
            messageWriter.Write($"The host has a different version of Town Of Us ({TownOfUs.GetVersion()})");
            messageWriter.EndMessage();
            innerNetClient.SendOrDisconnect(messageWriter);
            messageWriter.Recycle();
        }
示例#3
0
            public static void Postfix(AmongUsClient __instance)
            {
                if (AmongUsClient.Instance.AmHost)
                {
                    return;
                }

                // If I am client, send handshake
                PluginSingleton <TownOfUs> .Instance.Log.LogMessage($"AmongUsClient.OnGameJoined.Postfix - Am client, sending handshake");

                var messageWriter = MessageWriter.Get(SendOption.Reliable);

                messageWriter.StartMessage(6);
                messageWriter.Write(__instance.GameId);
                messageWriter.WritePacked(__instance.HostId);
                messageWriter.StartMessage(TOU_ROOT_HANDSHAKE_TAG);
                messageWriter.Write(AmongUsClient.Instance.ClientId);
                messageWriter.Write(TownOfUs.GetVersion());
                messageWriter.EndMessage();
                messageWriter.EndMessage();
                __instance.SendOrDisconnect(messageWriter);
                messageWriter.Recycle();
            }