コード例 #1
0
        private void __OnPlayerInfo(NetworkMessage message)
        {
            PlayerInfoMessage playerInfoMessage = message == null ? null : message.ReadMessage <PlayerInfoMessage>();

            if (playerInfoMessage == null)
            {
                return;
            }

            if (__players == null)
            {
                __players = new Dictionary <int, Player>();
            }

            __players[playerInfoMessage.index] = new Player(playerInfoMessage.playerIndex, playerInfoMessage.roomIndex);
        }
コード例 #2
0
        protected override bool _Register(NetworkReader reader, int connectionId, out short type, out int roomIndex, out int playerIndex)
        {
            if (!_GetPlayerInfo(reader, connectionId, out type, out roomIndex, out playerIndex))
            {
                return(false);
            }

            if (__rooms == null)
            {
                __rooms = new Pool <Room>();
            }

            Room room;

            if (!__rooms.TryGetValue(roomIndex, out room))
            {
                int length;
                if (_GetRoomInfo(reader, connectionId, roomIndex, out length))
                {
                    room = new Room(length, 0);

                    __rooms.Insert(roomIndex, room);
                }
                else
                {
                    return(false);
                }
            }

            if (connectionId >= 0)
            {
                Send(connectionId, (short)HostMessageType.RoomInfo, new RoomInfoMessage((short)roomIndex, (short)room.length, (short)room.count));

                PlayerInfoMessage message = new PlayerInfoMessage((short)nextNodeIndex, (short)roomIndex, (short)playerIndex);
                Send(connectionId, (short)HostMessageType.PlayerInfo, message);

                IEnumerable <KeyValuePair <int, ZG.Network.Node> > temp = GetRoom(roomIndex);
                if (temp != null)
                {
                    short        index;
                    Node         node;
                    Network.Node instance;
                    foreach (KeyValuePair <int, Network.Node> pair in temp)
                    {
                        instance = pair.Value;
                        if (instance != null)
                        {
                            index = instance.index;
                            if (GetNode(index, out node))
                            {
                                if (node.connectionId >= 0)
                                {
                                    Send(node.connectionId, (short)HostMessageType.PlayerInfo, message);
                                }

                                Send(connectionId, (short)HostMessageType.PlayerInfo, new PlayerInfoMessage(index, message.roomIndex, (short)pair.Key));
                            }
                        }
                    }
                }
            }

            return(true);
        }