示例#1
0
    private void __OnRegistered(ZG.Network.Node node)
    {
        if (node == null || __playerNames == null || __playerMap == null)
        {
            return;
        }

        string playerName;

        if (!__playerNames.TryGetValue(node.index, out playerName))
        {
            return;
        }

        Player player;

        if (!__playerMap.TryGetValue(playerName, out player))
        {
            return;
        }

        if (player.index >= 0 && player.index < 4)
        {
            if (__roomMap == null)
            {
                return;
            }

            Room room;
            if (!__roomMap.TryGetValue(player.roomName, out room) || room == null)
            {
                return;
            }

            Room.Player temp = room.Get(player.index);
            if (temp == null)
            {
                temp       = new Room.Player(room);
                temp.index = player.index;
            }

            temp.instance = node == null ? null : node.GetComponent <MahjongServerPlayer>();
        }
    }
示例#2
0
        private void __Remove(Node node)
        {
            ServerObject instance = node == null ? null : node.GetComponent <ServerObject>();

            Assert.IsNotNull(instance);
            if (instance == null || instance == this)
            {
                return;
            }

            Server host = __node == null ? null : __node.host as Server;

            Assert.IsNotNull(host);
            if (host == null)
            {
                return;
            }

            Server.Node temp;
            bool        result = host.GetNode(__node.index, out temp);

            Assert.IsTrue(result);
            if (!result)
            {
                return;
            }

            if (temp.connectionId >= 0)
            {
                --instance.__refCount;

                if (instance.__refCount == 0 && instance.onDisable != null)
                {
                    instance.onDisable();
                }

                --__refCount;
                if (__refCount == 0 && onDisable != null)
                {
                    onDisable();
                }
            }
            else
            {
                if (!host.GetNode(node.index, out temp))
                {
                    return;
                }

                if (temp.connectionId >= 0)
                {
                    --__refCount;
                    if (__refCount == 0 && onDisable != null)
                    {
                        onDisable();
                    }

                    --instance.__refCount;
                }
            }
        }
示例#3
0
        private void __Add(Node node)
        {
            ServerObject instance = node == null ? null : node.GetComponent <ServerObject>();

            Assert.IsNotNull(instance);
            if (instance == null || instance == this)
            {
                return;
            }

            Server host = __node == null ? null : __node.host as Server;

            Assert.IsNotNull(host);
            if (host == null)
            {
                return;
            }

            short index = __node.index;

            Server.Node temp;
            bool        result = host.GetNode(index, out temp);

            Assert.IsTrue(result);
            if (!result)
            {
                return;
            }

            if (temp.connectionId >= 0)
            {
                if (__refCount == 0 && onEnable != null)
                {
                    onEnable();
                }

                ++__refCount;

                if (instance.__refCount == 0 && instance.onEnable != null)
                {
                    instance.onEnable();
                }

                ++instance.__refCount;

                Delegate[] invocationList = instance.onInit == null ? null : instance.onInit.GetInvocationList();
                if (invocationList != null)
                {
                    Func <NetworkWriter, short> onInit;
                    foreach (Delegate invocation in invocationList)
                    {
                        onInit = invocation as Func <NetworkWriter, short>;
                        if (onInit != null)
                        {
                            host.Send(
                                temp.connectionId,
                                node.index,
                                onInit(instance.RpcStart()),
                                instance.__writer.AsArray(),
                                instance.__writer.Position);
                        }
                    }
                }
            }
            else
            {
                if (!host.GetNode(node.index, out temp))
                {
                    return;
                }

                if (temp.connectionId >= 0)
                {
                    if (__refCount == 0 && onEnable != null)
                    {
                        onEnable();
                    }

                    ++__refCount;

                    ++instance.__refCount;

                    Delegate[] invocationList = this.onInit == null ? null : this.onInit.GetInvocationList();
                    if (invocationList != null)
                    {
                        Func <NetworkWriter, short> onInit;
                        foreach (Delegate invocation in invocationList)
                        {
                            onInit = invocation as Func <NetworkWriter, short>;
                            if (onInit != null)
                            {
                                host.Send(
                                    temp.connectionId,
                                    index,
                                    onInit(RpcStart()),
                                    __writer.AsArray(),
                                    __writer.Position);
                            }
                        }
                    }
                }
            }
        }