forked from filipmaj1/CapcomDirectServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoom.cs
71 lines (63 loc) · 2.15 KB
/
Room.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Text;
namespace FMaj.CapcomDirectServer
{
class Room
{
public byte GameCode { get; }
public byte GenreCode { get; }
public ushort RoomNumber { get; }
public string RoomName { get; set; }
public ushort MaxUsers { get; }
public ushort Count { get => (ushort) members.Count; }
private List<Client> members = new List<Client>();
public Room(byte gamecode, byte genrecode, ushort roomNumber, string roomName, ushort maxUsers)
{
this.GameCode = gamecode;
this.GenreCode = genrecode;
this.RoomNumber = roomNumber;
this.RoomName = roomName;
this.MaxUsers = maxUsers;
}
public void Add(Client user)
{
lock (members)
{
members.Add(user);
foreach (Client userInRoom in members)
{
if (!user.Equals(userInRoom))
userInRoom.SendMessage(Capcom.ServerOpcodes.UpdateRoomInfo, Capcom.UpdateRoomInfoBytes(RoomNumber, 1, (ushort) members.Count));
}
}
}
public void Remove(Client user)
{
lock (members)
{
members.Remove(user);
foreach (Client userInRoom in members)
userInRoom.SendMessage(Capcom.ServerOpcodes.UpdateRoomInfo, Capcom.UpdateRoomInfoBytes(RoomNumber, 1, (ushort)members.Count));
}
}
public Client[] GetMembers()
{
lock (members)
{
Client[] currentMembers = new Client[members.Count];
members.CopyTo(currentMembers);
return currentMembers;
}
}
public void SendMessageToRoom(Client sender, byte[] message)
{
foreach (Client userInRoom in members)
userInRoom.SendMessage(Capcom.ServerOpcodes.ChatMessage, message);
}
public byte IsAvailable()
{
return Count <= MaxUsers ? (byte) 1 : (byte) 0;
}
}
}