Esempio n. 1
0
        private static void RPC_RequestLocationsDropThat(ZRpc rpc)
        {
            try
            {
                if (!ZNet.instance.IsServer())
                {
                    Log.LogWarning("Non-server instance received request for location data. Ignoring request.");
                    return;
                }

                Log.LogInfo($"Sending location data.");

                if (ZoneSystem.instance.m_locationInstances is null)
                {
                    Log.LogWarning("Unable to get locations from zonesystem to send to client.");
                    return;
                }

                var pck = new SimpleLocationPackage();

                ZPackage package = pck.Pack();

                DataTransferService.Service.AddToQueue(package, nameof(RPC_ReceiveLocationsDropThat), rpc);

                Log.LogInfo("Finished sending locations package.");
            }
            catch (Exception e)
            {
                Log.LogError("Unexpected error while attempting to create and send locations package from server to client.", e);
            }
        }
 public static IEnumerator ZoneHandler2(ZRpc rpc)
 {
     rpc.Invoke("ZoneHandler", new object[] {
         ZoneHandler.Serialize(rpc.GetSocket().GetHostName())
     });
     yield return(new WaitForSeconds(1));
 }
 public static IEnumerator Client2(ZRpc rpc)
 {
     rpc.Invoke("Client", new object[] {
         Client.Serialize(rpc.GetSocket().GetHostName())
     });
     yield return(new WaitForSeconds(1));
 }
Esempio n. 4
0
        private void ProvidePasswordPatch(ZNet self, ZRpc rpc, bool needPassword)
        {
            if (Environment.GetCommandLineArgs().Any(x => x.ToLower() == "+password"))
            {
                var args = Environment.GetCommandLineArgs();

                // find password argument index
                var index = 0;
                while (index < args.Length && args[index].ToLower() != "+password")
                {
                    index++;
                }

                index++;

                // is there a password after +password?
                if (index < args.Length)
                {
                    // do normal handshake
                    self.m_connectingDialog.gameObject.SetActive(false);
                    self.SendPeerInfo(rpc, args[index]);
                    return;
                }
            }
        }
Esempio n. 5
0
    // Token: 0x06000917 RID: 2327 RVA: 0x00043750 File Offset: 0x00041950
    public static object[] Deserialize(ZRpc rpc, ParameterInfo[] paramInfo, ZPackage pkg)
    {
        List <object> list = new List <object>();

        list.Add(rpc);
        ZRpc.Deserialize(paramInfo, pkg, ref list);
        return(list.ToArray());
    }
Esempio n. 6
0
    public static object[] Deserialize(long callerID, ParameterInfo[] paramInfo, ZPackage pkg)
    {
        List <object> parameters = new List <object>();

        parameters.Add((object)callerID);
        ZRpc.Deserialize(paramInfo, pkg, ref parameters);
        return(parameters.ToArray());
    }
Esempio n. 7
0
        /// <summary>
        ///     On RPC_PeerInfo on client, also ask server for admin status.
        /// </summary>
        /// <param name="orig"></param>
        /// <param name="self"></param>
        /// <param name="rpc"></param>
        /// <param name="pkg"></param>
        private void ZNet_RPC_PeerInfo(On.ZNet.orig_RPC_PeerInfo orig, ZNet self, ZRpc rpc, ZPackage pkg)
        {
            orig(self, rpc, pkg);

            if (ZNet.instance.IsClientInstance())
            {
                ZRoutedRpc.instance.InvokeRoutedRPC(ZNet.instance.GetServerPeer().m_uid, nameof(RPC_Jotunn_IsAdmin), false);
            }
        }
Esempio n. 8
0
        private static void RPC_DropThatReceiveDataTest(ZRpc rpc, ZPackage pkg)
        {
            int packageSize = pkg.Size();

            ReceivedCount++;
            ReceivedBytes += packageSize;

            Log.LogInfo($"Received package {ReceivedCount} with size {packageSize}. Total received: {ReceivedBytes}");
        }
        public static void OnReceiveMapDataInitial(ZRpc client, ZPackage mapData)
        {
            if (!Store.IsSharingMap())
            {
                return;
            }

            mapData.SetPos(0);

            var chunk = mapData.ReadInt();
            //Utility.Log("Client received initial map data by server chunk " + (chunk+1) + "/" + CHUNKS);

            var explored   = ExplorationDatabase.UnpackBoolArray(mapData, ExplorationDatabase.MapSizeSquared / CHUNKS);
            var startIndex = chunk * (ExplorationDatabase.MapSizeSquared / CHUNKS);

            for (var index = 0; index < explored.Length; index++)
            {
                if (explored[index])
                {
                    _Minimap.Explore(_Minimap._instance, (startIndex + index) % ExplorationDatabase.MapSize, (startIndex + index) / ExplorationDatabase.MapSize);
                }
            }

            var fogTexture = Traverse.Create((_Minimap._instance)).Field("m_fogTexture").GetValue() as Texture2D;

            fogTexture.Apply();


            _ZNet._instance.StartCoroutine(SendChunkToServer(client, chunk));


            // var explored = ExplorationDatabase.UnpackBoolArray(mapData);
            //
            // for (var index = 0; index < explored.Length; index++)
            // {
            //     if (explored[index])
            //     {
            //         _Minimap.Explore(_Minimap._instance, index % ExplorationDatabase.MapSize, index / ExplorationDatabase.MapSize);
            //     }
            // }
            //
            // var fogTexture =  Traverse.Create((_Minimap._instance)).Field("m_fogTexture").GetValue() as Texture2D;
            // fogTexture.Apply();
            //
            // explored = Traverse.Create(_Minimap._instance).Field("m_explored").GetValue() as bool[];
            // var z = ExplorationDatabase.PackBoolArray(explored);
            // if (_ZNet.IsServer(_ZNet._instance))
            // {
            //     OnClientInitialData(null, z);
            // }
            // else
            // {
            //     var znet =  Traverse.Create(typeof(ZNet)).Field("m_instance").GetValue() as ZNet;
            //     ZRpc server = _ZNet.GetServerRPC(znet);
            //     server.Invoke("OnClientInitialData", (object) z);
            // }
        }
Esempio n. 10
0
 private static void RPC_ShareLoadingScreen(ZRpc rpc, string screen)
 {
     Dbgl($"RPC_ShareLoadingScreen received");
     if (!ZNet.instance.IsServer())
     {
         secondsWaited = 0;
         context.StartCoroutine(LoadLoadingScreen(screen));
     }
 }
Esempio n. 11
0
        public static void RPC_Known(ZRpc rpc, ZPackage pkg)
        {
            ZNetPeer peer   = ZNet.instance.GetPeer(rpc);
            long     sender = peer.m_uid;

            int materialCount = LoadKnownFromPkg(sender, pkg, playerKnownMaterial);
            int recipeCount   = LoadKnownFromPkg(sender, pkg, playerKnownRecipes);

            Plugin.logger.LogInfo($"Received known from peer {sender}: {materialCount} materials / {recipeCount} recipes");
        }
Esempio n. 12
0
        public static void RPC_RequestKnown(ZRpc rpc)
        {
            requestedKnown = true;
            Player player = Player.m_localPlayer;

            if (player && playerLoaded)
            {
                SendKnown(player);
            }
        }
Esempio n. 13
0
        public static void Postfix(ZNet __instance, ZRpc rpc, ZDOID characterID)
        {
            if (!__instance.IsDedicated() && !__instance.IsServer())
            {
                return;
            }

            SendModVersionToClient(__instance.GetPeer(rpc).m_uid, MapSharingMadeEasy.instance.PluginVersion);
            SendConfigToClient(__instance.GetPeer(rpc).m_uid);
        }
        private static void onReceiveMapData(ZRpc client, ZPackage mapData)
        {
            int x = mapData.ReadInt();
            int y = mapData.ReadInt();

            var  m    = Traverse.Create(typeof(Minimap)).Field("m_instance").GetValue() as Minimap;
            bool flag = _Minimap.Explore(m, x, y);

            dirty = flag || dirty;
        }
Esempio n. 15
0
 // Token: 0x060007C5 RID: 1989 RVA: 0x0003D1C0 File Offset: 0x0003B3C0
 private ZDOMan.ZDOPeer FindPeer(ZRpc rpc)
 {
     foreach (ZDOMan.ZDOPeer zdopeer in this.m_peers)
     {
         if (zdopeer.m_peer.m_rpc == rpc)
         {
             return(zdopeer);
         }
     }
     return(null);
 }
Esempio n. 16
0
        private void WindowBuilder(int id)
        {
            GUI.DragWindow(new Rect(0, 0, windowWidth.Value, 20));
            GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(windowWidth.Value) });
            GUILayout.Label(windowTitleText, titleStyle);
            GUILayout.Label(string.Format(myCurrencyString.Value, string.Format(currencyString.Value, myCurrency)), currencyStyle);

            float width     = windowWidth.Value - 70;
            float itemWidth = width / packagesPerRow.Value;

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, new GUILayoutOption[] { GUILayout.Width(windowWidth.Value - 20) });
            GUILayout.Space(10);
            GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(width) });
            GUILayout.BeginHorizontal();
            for (int i = 0; i < storePackages.Count; i++)
            {
                if (i > 0 && i % packagesPerRow.Value == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.Space(10);
                    GUILayout.BeginHorizontal();
                }
                PackageInfo pi      = storePackages[i];
                string      texture = textureDict.ContainsKey(pi.type) ? pi.type : "Common";
                GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(itemWidth) });
                if (GUILayout.Button(textureDict[texture], new GUILayoutOption[] { GUILayout.Width(itemWidth), GUILayout.Height(itemWidth) }))
                {
                    if (myCurrency >= pi.price)
                    {
                        ZRpc serverRPC = ZNet.instance.GetServerRPC();
                        if (serverRPC != null)
                        {
                            Dbgl("Requesting store data");
                            JsonCommand command = new JsonCommand()
                            {
                                command   = "BuyPackage",
                                packageid = pi.id
                            };
                            string commandJson = JsonUtility.ToJson(command);
                            Dbgl(commandJson);
                            serverRPC.Invoke("SendServerRewardsJSON", new object[] { commandJson });
                        }
                    }
                }

                GUILayout.Label(string.Format(packageString.Value, pi.name, pi.price), labelStyle, new GUILayoutOption[] { GUILayout.Width(itemWidth) });
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
        }
Esempio n. 17
0
            public static void Postfix(ZNet __instance, ZRpc rpc)
            {
                ZNetPeer peer = Traverse.Create(__instance).Method("GetPeer", new object[] { rpc }).GetValue <ZNetPeer>();

                Dbgl($"Sending loading screen {serverLoadingScreen.Value}");


                peer.m_rpc.Invoke("ShareLoadingScreen", new object[]
                {
                    serverLoadingScreen.Value
                });
            }
Esempio n. 18
0
 private static void RPC_ReceiveConfigsDropThat(ZRpc rpc, ZPackage pkg)
 {
     Log.LogInfo("Received package.");
     try
     {
         CompressedPackage.Unpack(pkg);
     }
     catch (Exception e)
     {
         Log.LogError("Error while attempting to read received config package.", e);
     }
 }
Esempio n. 19
0
            private static void Postfix(ref ZNet __instance, ref ZRpc rpc)
            {
                ZNetPeer peer = __instance.GetPeer(rpc);

                if (peer.m_characterID.IsNone() || !ZNet.instance.IsServer() || !__instance.IsConnected(peer.m_uid) || ConnectedPlayers.Contains(peer.m_characterID.userID))
                {
                    return;
                }
                ConnectedPlayers.Add(peer.m_characterID.userID);

                ValheimEventHandler.OnPlayerJoined(GetPlayerInfoFromPeer(peer));
            }
Esempio n. 20
0
        // TODO: Move to ExplorationMapSync.cs
        public static void OnReceiveMapData(ZRpc client, ZPackage mapData)
        {
            mapData.SetPos(0);

            var x = mapData.ReadInt();
            var y = mapData.ReadInt();

            var m    = Traverse.Create(typeof(Minimap)).Field("m_instance").GetValue() as Minimap;
            var flag = _Minimap.Explore(m, x, y);

            _dirty = flag || _dirty;
        }
 private static void RPC_ReceiveLocationsSpawnThat(ZRpc rpc, ZPackage pkg)
 {
     Log.LogInfo("Received locations package.");
     try
     {
         CompressedPackage.Unpack <SimpleLocationPackage>(pkg);
     }
     catch (Exception e)
     {
         Log.LogError("Error while attempting to read received locations package.", e);
     }
 }
            // ReSharper disable once InconsistentNaming
            private static void Postfix(ZRpc rpc, ZNet __instance)
            {
                if (!Store.IsSharingMap())
                {
                    return;
                }

                if (__instance.IsServer())
                {
                    SendChunkToClient(rpc, 0);
                }
            }
Esempio n. 23
0
            private static void Prefix(ref ZNet __instance, ref ZRpc rpc)
            {
                ZNetPeer peer = __instance.GetPeer(rpc);

                if (peer.m_characterID.IsNone() || !ZNet.instance.IsServer() || !__instance.IsConnected(peer.m_uid))
                {
                    return;
                }
                ConnectedPlayers.Remove(peer.m_uid);

                ValheimEventHandler.OnPlayerDisconnected(GetPlayerInfoFromPeer(peer));
            }
 private static void RPC_SpawnThat_ReceiveLocalSpawnerConfigs(ZRpc rpc, ZPackage pkg)
 {
     Log.LogTrace("Received local spawner config package.");
     try
     {
         CompressedPackage.Unpack <LocalSpawnerConfigPackage>(pkg);
     }
     catch (Exception e)
     {
         Log.LogError("Error while attempting to read received config package.", e);
     }
 }
Esempio n. 25
0
 // Token: 0x060008FD RID: 2301 RVA: 0x00043010 File Offset: 0x00041210
 private void RPC_RoutedRPC(ZRpc rpc, ZPackage pkg)
 {
     ZRoutedRpc.RoutedRPCData routedRPCData = new ZRoutedRpc.RoutedRPCData();
     routedRPCData.Deserialize(pkg);
     if (routedRPCData.m_targetPeerID == this.m_id || routedRPCData.m_targetPeerID == 0L)
     {
         this.HandleRoutedRPC(routedRPCData);
     }
     if (this.m_server && routedRPCData.m_targetPeerID != this.m_id)
     {
         this.RouteRPC(routedRPCData);
     }
 }
Esempio n. 26
0
        public static void SendDataTest(ZRpc rpc)
        {
            for (int batch = 0; batch < 100; ++batch)
            {
                ZPackage package = new ZPackage();

                package.Write(new byte[500000]);

                Log.LogDebug($"Queueing test-package {batch}");

                DataTransferService.Service.AddToQueue(package, nameof(RPC_DropThatReceiveDataTest), rpc);
            }
        }
Esempio n. 27
0
        /// <summary>
        ///     Hook ZNet.RPC_PeerInfo on the server to send initial data
        /// </summary>
        /// <param name="self"></param>
        /// <param name="rpc"></param>
        /// <param name="__state"></param>
        private void ZNet_RPC_Pre_PeerInfo(ZNet self, ZRpc rpc, ref PeerInfoBlockingSocket __state)
        {
            PeerInfoBlockingSocket bufferingSocket = null;

            // Create buffering socket
            if (self.IsServer())
            {
                bufferingSocket = new PeerInfoBlockingSocket(rpc.GetSocket());
                rpc.m_socket    = bufferingSocket;
            }

            __state = bufferingSocket;
        }
Esempio n. 28
0
            private static bool RPC_PeerInfoPrefix(ZNet __instance, ZRpc rpc, ZPackage pkg)
            {
                if (__instance.IsServer() && Settings.EnabledForThisWorld)
                {
                    __instance.StartCoroutine(SendSettings(__instance, rpc, pkg));

                    return(false);
                }
                else if (__instance.IsServer())
                {
                    Log($"World doesn't use Better Continents, skipping version check and sync");
                }
                return(true);
            }
Esempio n. 29
0
        public static void RPC_AddKnownMaterial(ZRpc rpc, string material)
        {
            ZNetPeer         peer   = ZNet.instance.GetPeer(rpc);
            long             sender = peer.m_uid;
            HashSet <string> knownMaterial;

            if (!playerKnownMaterial.TryGetValue(sender, out knownMaterial))
            {
                Plugin.logger.LogWarning($"RPC_AddKnownMaterial: hashset is null for peer {sender}");
                return;
            }
            knownMaterial.Add(material);
            Plugin.logger.LogInfo($"Received add known material from peer {sender}: {material}");
        }
Esempio n. 30
0
        public static void RPC_AddKnownRecipe(ZRpc rpc, string recipe)
        {
            ZNetPeer         peer   = ZNet.instance.GetPeer(rpc);
            long             sender = peer.m_uid;
            HashSet <string> knownRecipes;

            if (!playerKnownRecipes.TryGetValue(sender, out knownRecipes))
            {
                Plugin.logger.LogWarning($"RPC_AddKnownRecipe: hashset is null for peer {sender}");
                return;
            }
            knownRecipes.Add(recipe);
            Plugin.logger.LogInfo($"Received add known recipe from peer {sender}: {recipe}");
        }