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!"); identity = id; }
public static void PlayerReady(int _fromClient, Packet _packet) { bool _ready = _packet.ReadBool(); ReadyHandler.ReadySetter(_fromClient, _ready); if (_ready) { ReadyHandler.totalReady++; ServerSend.Siap(ReadyHandler.totalReady, Server.readyDatabase.Count, "(wait)"); if (ReadyHandler.totalReady == Server.readyDatabase.Count) { //Console.WriteLine($"All player're ready: {RandomizeHandler.StuffRandomizer()} & {RandomizeHandler.ColorRandomizer()}"); ServerSend.Siap(ReadyHandler.totalReady, Server.readyDatabase.Count, "ready"); } } }
public static void SetDatabase(string codeRoom, int maxCategory, int maxQuestion) { List <int> numberTemp = new List <int>(); for (int i = 0; i < maxQuestion; i++) { int categoryResult = 0; int questionResult = 0; Random rand = new Random(DateTime.Now.Millisecond); do { categoryResult = rand.Next(0, maxCategory); questionResult = rand.Next(0, maxQuestion); } while (numberTemp.Contains(questionResult)); numberTemp.Add(questionResult); //Console.WriteLine($"Category: {categoryResult} - Question: {questionResult}"); ServerSend.TriviaDatabaseBroadcast(codeRoom, categoryResult, questionResult); } }
public void SendtoGame(string uname) { player = new ClientData.Position(id, uname, new Vector3(0, 0, 0)); foreach (Client client in Server.clients.Values) { if (client.player != null) { if (client.id != id) { ServerSend.PositionBroadcast(id, client.player); } } } foreach (Client client in Server.clients.Values) { if (client.player != null) { ServerSend.PositionBroadcast(client.id, player); } } }
public static void ColorReceived(int _fromClient, Packet _packet) { bool warna = _packet.ReadBool(); ServerSend.SendColor(); }
public static void ChatboxReceived(int _fromClient, Packet _packet) { ClientData.Chatbox _chatbox = _packet.ReadObject <ClientData.Chatbox>(); ServerSend.BroadcastChatbox(_chatbox.username, _chatbox.message); }