예제 #1
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;
        }
예제 #2
0
        private void ZNet_RPC_Post_PeerInfo(ZNet self, ZRpc rpc, ref PeerInfoBlockingSocket __state)
        {
            PeerInfoBlockingSocket bufferingSocket = __state;

            // Send initial data
            if (self.IsServer())
            {
                ZNetPeer peer = self.GetPeer(rpc);

                if (peer == null || !peer.IsReady())
                {
                    Logger.LogInfo($"Peer has disconnected. Skipping initial data send.");
                    return;
                }

                Logger.LogInfo($"Sending initial data to peer #{peer.m_uid}");

                IEnumerator SynchronizeInitialData()
                {
                    var result = ZNet.instance.m_adminList.Contains(peer.m_socket.GetHostName());

                    Logger.LogDebug($"Admin status: {(result ? "Admin" : "No Admin")}");
                    var adminPkg = new ZPackage();

                    adminPkg.Write(result);
                    yield return(ZNet.instance.StartCoroutine(AdminRPC.SendPackageRoutine(peer.m_uid, adminPkg)));

                    var pkg = GenerateConfigZPackage(true, GetSyncConfigValues());

                    yield return(ZNet.instance.StartCoroutine(ConfigRPC.SendPackageRoutine(peer.m_uid, pkg)));

                    if (peer.m_rpc.GetSocket() is PeerInfoBlockingSocket currentSocket)
                    {
                        peer.m_rpc.m_socket = currentSocket.Original;
                    }

                    bufferingSocket.finished = true;

                    foreach (ZPackage package in bufferingSocket.Package)
                    {
                        bufferingSocket.Original.Send(package);
                    }
                }

                self.StartCoroutine(SynchronizeInitialData());
            }
        }
예제 #3
0
 private static void ZNet_RPC_Post_PeerInfo(ZNet __instance, ZRpc rpc, ref PeerInfoBlockingSocket __state) => Instance.ZNet_RPC_Post_PeerInfo(__instance, rpc, ref __state);