Пример #1
0
            static void Prefix(RoutedRPCData data)
            {
                ZNetPeer peer    = ZNet.instance.GetPeer(data.m_senderPeerID);
                var      steamid = "";

                try {
                    steamid = peer.m_rpc.GetSocket().GetHostName();
                } catch {}

                if (data?.m_methodHash == sayMethodHash)
                {
                    try {
                        var      zdoData     = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos         = zdoData.GetPosition();
                        ZPackage package     = new ZPackage(data.m_parameters.GetArray());
                        int      messageType = package.ReadInt();
                        string   userName    = package.ReadString();
                        string   message     = package.ReadString();
                        message = (message == null ? "" : message).Trim();

                        if (message.StartsWith("/pin"))
                        {
                            var messageParts = message.Split(' ');
                            var pinType      = "dot";
                            var startIdx     = 1;
                            if (messageParts.Length > 1 && ALLOWED_PINS.Contains(messageParts[1]))
                            {
                                pinType  = messageParts[1];
                                startIdx = 2;
                            }
                            var pinText = "";
                            if (startIdx < messageParts.Length)
                            {
                                pinText = String.Join(" ", messageParts, startIdx, messageParts.Length - startIdx);
                            }
                            if (pinText.Length > 20)
                            {
                                pinText = pinText.Substring(0, 20);
                            }
                            var safePinsText = Regex.Replace(pinText, @"[^a-zA-Z0-9 ]", "");

                            var timestamp = DateTime.Now - unixEpoch;
                            var pinId     = $"{timestamp.TotalMilliseconds}-{UnityEngine.Random.Range(1000, 9999)}";
                            mapDataServer.AddPin(steamid, pinId, pinType, userName, pos, safePinsText);

                            var usersPins       = mapDataServer.pins.FindAll(pin => pin.StartsWith(steamid));
                            var numOverflowPins = usersPins.Count - WebMapConfig.MAX_PINS_PER_USER;
                            for (var t = numOverflowPins; t > 0; t--)
                            {
                                var pinIdx = mapDataServer.pins.FindIndex(pin => pin.StartsWith(steamid));
                                mapDataServer.RemovePin(pinIdx);
                            }
                            SavePins();
                        }
                        else if (message.StartsWith("/undoPin"))
                        {
                            var pinIdx = mapDataServer.pins.FindLastIndex(pin => pin.StartsWith(steamid));
                            if (pinIdx > -1)
                            {
                                mapDataServer.RemovePin(pinIdx);
                                SavePins();
                            }
                        }
                        else if (message.StartsWith("/deletePin"))
                        {
                            var messageParts = message.Split(' ');
                            var pinText      = "";
                            if (messageParts.Length > 1)
                            {
                                pinText = String.Join(" ", messageParts, 1, messageParts.Length - 1);
                            }

                            var pinIdx = mapDataServer.pins.FindLastIndex(pin => {
                                var pinParts = pin.Split(',');
                                return(pinParts[0] == steamid && pinParts[pinParts.Length - 1] == pinText);
                            });

                            if (pinIdx > -1)
                            {
                                mapDataServer.RemovePin(pinIdx);
                                SavePins();
                            }
                        }
                        //Debug.Log("SAY!!! " + messageType + " | " + userName + " | " + message);
                    } catch {}
                }
                else if (data?.m_methodHash == chatMessageMethodHash)
                {
                    try {
                        ZPackage package     = new ZPackage(data.m_parameters.GetArray());
                        Vector3  pos         = package.ReadVector3();
                        int      messageType = package.ReadInt();
                        string   userName    = package.ReadString();
                        // string message = package.ReadString();
                        // message = (message == null ? "" : message).Trim();

                        if (messageType == (int)Talker.Type.Ping)
                        {
                            mapDataServer.BroadcastPing(data.m_senderPeerID, userName, pos);
                        }
                        // Debug.Log("CHAT!!! " + pos + " | " + messageType + " | " + userName + " | " + message);
                    } catch {}
                }
            }
Пример #2
0
            static void Prefix(RoutedRPCData data)
            {
                var targetName = "";
                ZDO targetZDO;

                if (!data.m_targetZDO.IsNone())
                {
                    try
                    {
                        targetZDO  = ZDOMan.instance.GetZDO(data.m_targetZDO);
                        targetName = targetZDO.m_type.ToString();
                    }
                    catch { }
                }


                ZNetPeer peer    = ZNet.instance.GetPeer(data.m_senderPeerID);
                var      steamid = "";

                try {
                    steamid = peer.m_rpc.GetSocket().GetHostName();
                } catch {}

                if (data?.m_methodHash == "Say".GetStableHashCode())
                {
                    // private void RPC_Say(long sender, int ctype, string user, string text)

                    try
                    {
                        var      zdoData     = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos         = zdoData.GetPosition();
                        ZPackage package     = new ZPackage(data.m_parameters.GetArray());
                        int      messageType = package.ReadInt();
                        string   userName    = package.ReadString();
                        string   message     = package.ReadString();
                        message = (message == null ? "" : message).Trim();

                        if (message.StartsWith("/pin"))
                        {
                            var messageParts = message.Split(' ');
                            var pinType      = "dot";
                            var startIdx     = 1;
                            if (messageParts.Length > 1 && ALLOWED_PINS.Contains(messageParts[1]))
                            {
                                pinType  = messageParts[1];
                                startIdx = 2;
                            }
                            var pinText = "";
                            if (startIdx < messageParts.Length)
                            {
                                pinText = String.Join(" ", messageParts, startIdx, messageParts.Length - startIdx);
                            }
                            if (pinText.Length > 40)
                            {
                                pinText = pinText.Substring(0, 40);
                            }
                            var safePinsText = Regex.Replace(pinText, @"[^a-zA-Z0-9 ]", "");
                            var uuId         = Guid.NewGuid();
                            var pinId        = uuId.ToString();
                            mapDataServer.AddPin(steamid, pinId, pinType, userName, pos, safePinsText);

                            var usersPins = mapDataServer.pins.FindAll(pin => pin.StartsWith(steamid));

                            var numOverflowPins = usersPins.Count - WebMapConfig.MAX_PINS_PER_USER;
                            for (var t = numOverflowPins; t > 0; t--)
                            {
                                var pinIdx = mapDataServer.pins.FindIndex(pin => pin.StartsWith(steamid));
                                // mapDataServer.RemovePin(pinIdx);
                                harmonyLog.LogInfo($"To many pins, deleting oldest one (ONLY DEBUG; WILL NOT DO)");
                            }

                            SavePins();
                        }
                        else if (message.StartsWith("/undoPin"))
                        {
                            var pinIdx = mapDataServer.pins.FindLastIndex(pin => pin.StartsWith(steamid));
                            if (pinIdx > -1)
                            {
                                mapDataServer.RemovePin(pinIdx);
                                SavePins();
                            }
                        }
                        else if (message.StartsWith("/deletePin"))
                        {
                            var messageParts = message.Split(' ');
                            var pinText      = "";
                            if (messageParts.Length > 1)
                            {
                                pinText = String.Join(" ", messageParts, 1, messageParts.Length - 1);
                            }

                            var pinIdx = mapDataServer.pins.FindLastIndex(pin => {
                                var pinParts = pin.Split(',');
                                return(pinParts[0] == steamid && pinParts[pinParts.Length - 1] == pinText);
                            });

                            if (pinIdx > -1)
                            {
                                mapDataServer.RemovePin(pinIdx);
                                SavePins();
                            }
                        }
                        else if (!message.StartsWith("/"))
                        {
                            mapDataServer.Broadcast($"say\n{messageType}\n{userName}\n{message}");
                            harmonyLog.LogInfo($"say\n{messageType}\n{userName}\n{message} / target={targetName}");
                        }
                    }
                    catch
                    {
                        harmonyLog.LogError($"Say() exception");
                    }
                }
                else if (data?.m_methodHash == "ChatMessage".GetStableHashCode())
                {
                    // private void RPC_ChatMessage(long sender, Vector3 position, int type, string name, string text)
                    try
                    {
                        ZPackage package     = new ZPackage(data.m_parameters.GetArray());
                        Vector3  pos         = package.ReadVector3();
                        int      messageType = package.ReadInt();
                        string   userName    = package.ReadString();
                        string   message     = package.ReadString();
                        message = (message == null ? "" : message).Trim();

                        if (messageType == (int)Talker.Type.Ping)
                        {
                            mapDataServer.BroadcastPing(data.m_senderPeerID, userName, pos);
                        }
                        else
                        {
                            mapDataServer.Broadcast($"chat\n{messageType}\n{userName}\n{pos}\n{message}");
                            harmonyLog.LogInfo($"ChatMessage() chat\n{messageType}\n{userName}\n{pos}\n{message} / target={targetName}");
                        }
                    }
                    catch
                    {
                        harmonyLog.LogError($"ChatMessage() exception");
                    }
                }
                else if (data?.m_methodHash == "OnDeath".GetStableHashCode())
                {
                    // private void RPC_OnDeath(long sender)
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        mapDataServer.Broadcast($"ondeath\n{peer.m_playerName}");
                        harmonyLog.LogInfo($"RPC_OnDeath() -- {peer.m_playerName} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_OnDeath() exception");
                    }
                }
                else if (data?.m_methodHash == "Message".GetStableHashCode())
                {
                    // private void RPC_Message(long sender, int type, string msg, int amount)
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        int    messageType = package.ReadInt();
                        string msg         = package.ReadString();
                        int    amount      = package.ReadInt();

                        mapDataServer.Broadcast($"message\n{peer.m_playerName}\n{messageType}\n{msg}\n{amount}");
                        harmonyLog.LogInfo($"RPC_Message() -- {peer.m_playerName} / {msg} - {amount} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_Message() exception");
                    }
                }

                else if (data?.m_methodHash == "DamageText".GetStableHashCode())
                {
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        //float v = package.Read();
                        //bool alerted = package.ReadBool();
                        var pkg = package.ReadPackage();

                        DamageText.TextType type   = (DamageText.TextType)pkg.ReadInt();
                        Vector3             vector = pkg.ReadVector3();
                        float dmg  = pkg.ReadSingle();
                        bool  flag = pkg.ReadBool();

                        harmonyLog.LogInfo($"RPC_DamageText() -- {peer.m_playerName} / type={type} / pos={vector} / dmg={dmg} / flag={flag} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_DamageText() exception");
                    }
                }
                else if (data?.m_methodHash == "Damage".GetStableHashCode())
                {
                    try
                    {
                        var      zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        var      pos     = zdoData.GetPosition();
                        ZPackage package = new ZPackage(data.m_parameters.GetArray());

                        harmonyLog.LogInfo($"RPC_Damage() -- {peer.m_playerName} / target={targetName}");
                    }
                    catch
                    {
                        harmonyLog.LogError($"RPC_Damage() exception");
                    }
                }
                else if (data?.m_methodHash == "DestroyZDO".GetStableHashCode())
                {
                    try
                    {
                        // supress
                        //ZPackage pkg = new ZPackage(data.m_parameters.GetArray());
                        //var pkg2 = pkg.ReadPackage();
                        //var numberofitems = pkg2.ReadInt();
                        //for (int i = 0; i < numberofitems; i++)
                        //{
                        //    ZDOID uid = pkg.ReadZDOID();

                        //}
                        //harmonyLog.LogInfo($"DestroyZDO() -- {peer.m_playerName} / numberofitems={numberofitems} / target={targetName}");
                    }
                    catch (Exception e)
                    {
                        harmonyLog.LogError($"DestroyZDO() exception " + e);
                    }
                }
                else if (data?.m_methodHash == "SetEvent".GetStableHashCode())
                {
                    try
                    {
                        //   var zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
                        //   var pos = zdoData.GetPosition();

                        ZPackage pkg = new ZPackage(data.m_parameters.GetArray());

                        var eventName = pkg.ReadString();
                        var time      = pkg.ReadSingle();
                        var eventPos  = pkg.ReadVector3();


                        if (!eventName.IsNullOrEmpty())
                        {
                            harmonyLog.LogInfo($"SetEvent() -- eventName={eventName} / time={time} / eventPos={eventPos} / target={targetName}");
                        }
                    }
                    catch (Exception e)
                    {
                        harmonyLog.LogError($"SetEvent() exception " + e);
                    }
                }
                else
                {
                    // Debug


                    //var methods = new List<string>() { "Jump", "OnJump", "SetMoveDir", "AddDPS", "AddFire", "BlockAttack", "UseStamina", "OnTargeted", "SetHealth", "SetCrouch",
                    //    "SetLookDir","SetRun", "Stagger", "Grow", "Shake", "CreateFragments", "RemotePrint","Pickup","Move","Die","Destroy","Awake","Loot","AddOre","EmptyProcessed",
                    //    "Interact","Hit","Create","Start","UseItem","UpdateTeleport","UseDoor","DropItem","AddNoise","Alert","Pick","Forward","Stop","OnHit","AddStatusEffect",
                    //    "Heal","AddFuel","OnNearProjectileHit","SleepStop","SleepStart","Ping", "Pong","DiscoverLocationRespons", "DiscoverClosestLocation",
                    //    "DestroyZDO","RequestZDO","SpawnObject","SetGlobalKey","GlobalKeys","LocationIcons","SetOwner","Extract","ResetCloth","SetTamed","RequestOpen","OpenRespons",
                    //    "RequestTakeAll", "TakeAllRespons","RequestOpen","SetSlotVisual","RemoveDoneItem","AddItem","Tap","Pickup","RequestPickup","Nibble","Step","SetPicked",
                    //    "ApplyOperation"


                    //};
                    //bool found = false;
                    //foreach (string method in methods)
                    //{
                    //    if (data?.m_methodHash == method.GetStableHashCode())
                    //    {
                    //        found = true;
                    //        harmonyLog.LogInfo($" -> DEBUG: {method}() ");
                    //    }

                    //}

                    //if (!found)
                    //{
                    //    // Unknown RPC message
                    //    harmonyLog.LogInfo($"<unknown rpc message> hash={data.m_methodHash}");
                    //}
                }
            }