public bool sendGameRequest(Int32 player1id, Int32 player2id) { ServerClient senderclinet = new ServerClient(lobby.getbyId(player1id)); Socket socketsendto = clientsockets[player2id - 1]; socketsendto.Send(new ASCIIEncoding().GetBytes(senderclinet.name + " szeretne " + senderclinet.gametype + " jatekot játszani!")); return recieveReaction(socketsendto,100); }
public ServerClient(ServerClient client) { this.id = client.id; this.port = client.port; this.ip = client.ip; this.name = client.name; this.gametype = client.gametype; }
private static void ClientAntwort(ServerClient Client, TCP_Protocoll Antwort) { Console.WriteLine("##--##--##--##--##--##--##--##--##--##--##"); string EnumName = Enum.GetName(typeof(TCP_Protocoll.HeaderData), Antwort.ProtocolType); switch (Antwort.ProtocolType) { case TCP_Protocoll.HeaderData.Error: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR"); Console.WriteLine("Client ID: " + Client.ClientID.ToString()); Console.WriteLine("Type: " + EnumName); Console.WriteLine("Int-Type: " + ((int)Antwort.ProtocolType).ToString()); Console.WriteLine("Message: " + Antwort.Data); Console.ForegroundColor = ConsoleColor.White; Client.Disconnect(); break; case TCP_Protocoll.HeaderData.Broadcast: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("BROADCAST"); ServerClient.SendToAllClients(Antwort, Client.ClientID); Console.WriteLine("Client ID: " + Client.ClientID.ToString()); Console.WriteLine("Type: " + EnumName); Console.WriteLine("Message: " + Antwort.Data); Console.ForegroundColor = ConsoleColor.White; break; default: Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Client ID: " + Client.ClientID.ToString()); Console.WriteLine("Type: " + EnumName); Console.WriteLine("Message: " + Antwort.Data); Console.ForegroundColor = ConsoleColor.White; break; } }
/// Die Daten von den Clients werden verarbeitet public void HandleData(ServerClient client, Command command) { Console.WriteLine("Daten erhalten! ID: " + command.Identifier); /// Wird angezeigt, wenn ein Daten erhalten worden sind if (command.Identifier == "sendMessage") { List <Tuple <string, string> > messageDatas = new List <Tuple <string, string> >(); if (ReceivedMessages.ContainsKey(client.Name)) { messageDatas = ReceivedMessages[client.Name]; ReceivedMessages.Remove(client.Name); } messageDatas.Add(new Tuple <string, string>(command.Arguments[0], command.Arguments[1])); ReceivedMessages.Add(client.Name, messageDatas); ServerClient receiver = GetClientByName(command.Arguments[0]); if (receiver != null) { receiver.Send(new Command("sendText", client.Name, command.Arguments[1])); } } else if (command.Identifier == "sendName") { client.Name = command.Arguments[0]; } }
// Leer informacion que llega al servidor private void OnIncomingData(ServerClient c, string data) { string[] aData = data.Split('|'); //login if (c.clientName != null) { //Program.form.DebugTextBox.Text += "\r\nClient '" + c.clientName + "' sent command: " + data; } else { Program.form.DebugTextBox.Text += "\r\nNuevo cliente tratando de unirse al servidor. Solicitud autenticacion."; if (aData[0] == "YoSoy") { bool authenticated = Database.AuthenticateUser(aData[1], aData[2]); if (!authenticated) { if (!Database.existUser(aData[1])) { Database.addUser(aData[1], aData[2]); c.clientName = aData[1]; c.id = Database.getId(aData[1]); Program.form.DebugTextBox.Text += "\r\nUsuario Autenticado"; Broadcast("Autenticado|", c); } } else if (authenticated) { foreach (ServerClient client in clients) { if (aData[1] == client.clientName) { Program.form.DebugTextBox.Text += "\r\nEste usuario ya esta conectado"; c.tcp.Close(); disconnectList.Add(c); return; } } c.clientName = aData[1]; c.id = Database.getId(aData[1]); Program.form.DebugTextBox.Text += "\r\nUsuario Autenticado"; Broadcast("Autenticado|", c); } else { Program.form.DebugTextBox.Text += "\r\nAuntenticacion de usuario fallida. "; c.tcp.Close(); disconnectList.Add(c); } return; } } //gameplay commands switch (aData[0]) { case "SolicitudSincronizacion": SynchronizeUnits(c, aData[1]); // SynchronizeBalon(c); break; case "Jugar": Unit unit = new Unit(); unit.clientName = c.clientName; unit.clientId = c.id; //give a new ID to the new units int newid = 0; //if (c.id%2!=0) unit.unitID = 0; //else unit.unitID = 1; foreach (Unit u in units) { if (u.unitID >= newid) { newid = u.unitID + 1; } } unit.unitID = newid; units.Add(unit); if (units.Count == 1) { unit.unitPositionX = 3.37f; unit.unitPositionY = 5.5f; } else if (units.Count == 2) { unit.unitPositionX = 14.68f; unit.unitPositionY = 5.5f; } Broadcast("UnidadAgregada|" + c.clientName + "|" + unit.unitID + "|" + unit.unitPositionX + "|" + unit.unitPositionY + "|" + c.id, clients); break; case "Moving": if (aData[1].Equals("balon")) { Broadcast("ballMoved|" + c.clientName + "|" + aData[1] + "|" + aData[2] + "|" + aData[3], clients); int ball; Int32.TryParse(aData[1], out ball); float X; float Y; float.TryParse(aData[2], out X); float.TryParse(aData[3], out Y); balon.ballPositionX = X; balon.ballPositionY = Y; balon.clientName = c.clientName; } else { Broadcast("UnidadMovida|" + c.clientName + "|" + aData[1] + "|" + aData[2] + "|" + aData[3], clients); int id; Int32.TryParse(aData[1], out id); float parsedX; float parsedY; float.TryParse(aData[2], out parsedX); float.TryParse(aData[3], out parsedY); foreach (Unit u in units) { if (u.unitID == id) { // Console.WriteLine(u.unitID+""); // Console.WriteLine(parsedX + ""); // Console.WriteLine(parsedY + ""); u.unitPositionX = parsedX; u.unitPositionY = parsedY; } } //Program.form.DebugTextBox.Text += "\r\n" + parsedX + " " + parsedY; } break; case "Goal": string GoalsAmount = aData[1]; Broadcast("ChangeMarker|" + c.clientName + "|" + GoalsAmount, clients); break; default: //Program.form.DebugTextBox.Text += "\r\nReceived unknown signal => skipping"; break; } }
public Message(ServerClient Sender, string Body) { sender = Sender; this.Body = Body; UserId = sender.UserId.ToString(); }
public static ServerClient CreateClient(TcpClient tclient) { ServerClient client = new ServerClient(tclient); return(client); }
private void ManageDisconnectedClient(ServerClient client) { client.tcp.Close(); disconnectClients.Add(client); clients.Remove(client); }
private void OnClientReadPacket(ServerClient client, byte[] data) { ClientReadPacket?.Invoke(this, client, data); }
private void acceptConnection(Int32 _inputsize) { int clientid = clientsockets.Count; Socket clinetsocket = clientsockets[clientid-1]; ServerInfoEventArgs args = new ServerInfoEventArgs(); args.consoleinfo = "Connection accepted from " + clinetsocket.RemoteEndPoint + "\n"; OnNeedLog(args); ServerClient client = new ServerClient(); client.id = clientid; client.port = ((IPEndPoint)clinetsocket.RemoteEndPoint).Port.ToString(); client.ip = ((IPEndPoint)clinetsocket.RemoteEndPoint).Address.ToString(); client.name = recieveData(clinetsocket,_inputsize); // itt várakozik az inputra client.gametype = ""; lobby.add(client); clinetsocket.Send(new ASCIIEncoding().GetBytes("Users in the lobby.\n" + lobby.getClientsName())); }
private void OnClientStateChanged(ServerClient client, bool connected) { ClientStateChanged?.Invoke(this, client, connected); }
public void add(ServerClient client) { clients.Add(client); }
public Message(ServerClient Sender, string Body) { sender = Sender; this.Body = Body; userName = sender?.userName; }
public Game(ServerClient currplayer, ServerClient secondplayer, Object gamefiled) { this.currplayer = currplayer; this.secondplayer = secondplayer; this.gamefiled = gamefiled; }
//Wird aufgerufen, wenn ein Client den Server verlässt public void HandleDisconnect(ServerClient client) { Clients.Remove(client); Console.WriteLine("Client hat den Server verlassen! Name: " + client.Name); /// Wird angezeigt, wenn ein Client den Server verlässt }
private void OnClientWriteProgressChanged(ServerClient client, double progress, int bytesWritten, int bytesToWrite) { ClientWriteProgressChanged?.Invoke(this, client, progress, bytesWritten, bytesToWrite); }
private void OnClientWritePacket(ServerClient client, int size) { ClientWritePacket?.Invoke(this, client, size); }
private void OnClientReadProgressChanged(ServerClient client, double progress, int bytesRead, int bytesToRead) { ClientReadProgressChanged?.Invoke(this, client, progress, bytesRead, bytesToRead); }
private void AddUser(bool serverState, ServerClient client) { client.GetUserName(serverState); users.Add(client.userName, client.UserId); userClients.Add(client); }
public void AddClientToDictionary(ServerClient client) { userDictionary.Add(userIdCounter, client); client.UserId = userIdCounter; userIdCounter++; }
public void remove(ServerClient client) { clients.Remove(client); }
private void OnClientExceptionThrown(ServerClient client, Exception ex) { ClientExceptionThrown?.Invoke(this, client, ex); }