//5 public static void RoomChatMessage(int _fromClient, Packet _packet) { string _msg = _packet.ReadString(); if (_msg.Length < 1) { return; } if (Server.clients[_fromClient].joinedRoomId == 0) { return; } ServerSend.RoomChatMessage(_fromClient, _msg); return; }
public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); ServerSend.Welcome(id, "Welcome to the server!"); }
static void Main(string[] args) { Console.Title = Constants.SERVERNAME; isRunning = true; Thread mainThread = new Thread(new ThreadStart(MainThread)); mainThread.Start(); Thread lobbyThread = new Thread(new ThreadStart(LobbyThread)); lobbyThread.Start(); Server.Start(Constants.MAXSERVERPLAYER, Constants.MAXROOMS, Constants.PORT); string _input; do { _input = Console.ReadLine(); string[] _str = _input.Split(' '); switch (_str[0]) { case "say": string _msg = String.Empty; for (int i = 1; i < _str.Length; i++) { _msg += _str[i] + " "; } ServerSend.LobbyServerMessage(_msg); break; default: break; } } while (true); }
public void SendIntoGame(string _playerName) { player = new Player(id, _playerName, new Vector3(0, 0, 0)); foreach (Client _client in Server.clients.Values) { if (_client.player != null) { if (_client.id != id) { ServerSend.SpawnPlayer(id, _client.player); } } } foreach (Client _client in Server.clients.Values) { if (_client.player != null) { ServerSend.SpawnPlayer(_client.id, player); } } }
//3 public static void RoomCreate(int _fromClient, Packet _packet) { int _roomId = Util.GetEmptyRoomId(); bool isJoin = false; string _name = _packet.ReadString(); bool _isPrivate = _packet.ReadBool(); string _password = _packet.ReadString(); if (_roomId == 0) { ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; } isJoin = Server.rooms[_roomId].JoinPlayer(_fromClient); if (isJoin) { Server.rooms[_roomId].SetRoom(_name, _isPrivate, _password); Console.WriteLine($"(userName: {Server.clients[_fromClient].userName}, clientId: {_fromClient}) create Room. (roomid: {_roomId}, roomName: {_name})."); } ServerSend.SendRoomJoinStatus(_fromClient, isJoin); return; }
public static void RoomListUpdate() { ServerSend.SendRoomList(); }