Пример #1
0
        static void CreateRoom(Connection conn, HazelReader reader)
        {
            UserInfo    info   = userByConnection [conn];
            HazelWriter writer = new HazelWriter();

            writer.WriteByte(3);
            if (info.room > 0 || info.name == null)
            {
                writer.Write(-1);
                conn.SendBytes(writer.bytes);
                return;
            }
            while (rooms.ContainsKey(lastRoomNumber))
            {
                lastRoomNumber++;
            }
            int    roomNumber = lastRoomNumber;
            string password   = reader.ReadString();

            rooms.Add(roomNumber, new Room(roomNumber, reader.ReadString())
            {
                type       = reader.ReadInt(),
                maxPlayers = reader.ReadInt(),
                password   = reader.ReadString()
            });
            int id = rooms [roomNumber].AddUser(info, password);

            info.room = roomNumber;
            Console.WriteLine(conn.EndPoint.ToString() + " created room " + roomNumber);
            writer.Write(roomNumber);
            writer.Write(id);
            conn.SendBytes(writer.bytes);
        }
Пример #2
0
    void RoomListReply(Connection conn, HazelReader reader)
    {
        int count = reader.ReadInt();

        Debug.Log("there are " + count + " rooms");
        rooms.Clear();
        while (count > 0)
        {
            rooms.Add(reader.ReadRoomInfo());
            count--;
        }
        foreach (Transform t in roomListEntryHolder)
        {
            Destroy(t.gameObject);
        }
        foreach (RoomInfo r in rooms)
        {
            RoomListEntry re = ((GameObject)Instantiate(roomListEntryPrefab)).GetComponent <RoomListEntry> ();
            re.transform.SetParent(roomListEntryHolder, false);
            re.name.text        = r.number + ". " + r.name;
            re.roomNumber       = r.number;
            re.playerCount.text = r.curPlayers + "/" + r.maxPlayers;
            if (r.hasPassword)
            {
                re.hasPassword.SetActive(true);
            }
            if (r.playing)
            {
                re.playing.SetActive(true);
            }
        }
    }
Пример #3
0
    void MoveRoom(Connection conn, HazelReader reader)
    {
        int reply = reader.ReadInt();

        if (reply < 0)
        {
            if (reply == -1)
            {
                PopupLog("You have been kicked.");
            }
            else if (reply == -2)
            {
                PopupLog("Room full");
            }
            else if (reply == -3)
            {
                PopupLog("Wrong password. If the room seem to have no password, try refreshing.");
            }
            else if (reply == -4)
            {
                PopupLog("Room not found");
            }
            else if (reply == -5)
            {
                PopupLog("Room is either full or already playing.");
            }
            else
            {
                PopupLog("Unknown error : " + reply + "\nTry restarting");
            }
        }
    }
Пример #4
0
        static void JoinRoom(Connection conn, HazelReader reader)
        {
            UserInfo    info   = userByConnection [conn];
            HazelWriter writer = new HazelWriter();

            writer.WriteByte(3);
            int roomNumber = reader.ReadInt();

            if (info.name == null || (info.room > 0 && info.room != roomNumber))
            {
                writer.Write(-1);
                conn.SendBytes(writer.bytes);
                return;
            }
            if (!rooms.ContainsKey(roomNumber))
            {
                writer.Write(-2);
                conn.SendBytes(writer.bytes);
                RoomList(conn, reader);
                return;
            }
            string password = reader.ReadString();
            int    id       = rooms [roomNumber].AddUser(info, password);

            if (id > -1)
            {
                //join successful
                info.room = roomNumber;
                writer.Write(roomNumber);
                writer.Write(id);
                conn.SendBytes(writer.bytes);
            }
            else
            {
                writer.Write(id);
                RoomList(conn, reader);
                conn.SendBytes(writer.bytes);
            }
        }