public void SendToGoupe(string groupName) { if (tickMessages.ChatDataPackages.Count > 0) { //DEBUG if (chatGUI != null) { foreach (var item in tickMessages.ChatDataPackages) { chatGUI.chatHistorie.Add(item.Target + " : " + item.port + " : " + item.Message); } } byte[] mes = TCPHelper.MessageBytes(tickMessages); //skal finde gruppen for (int i = 0; i < groups.Count; i++) { if (groups[i].GroupName == groupName) { for (int y = 0; y < groups[i].Members.Count; y++) { groups[i].Members[y].SendToClient(mes); } } } } }
public void Message(string msg) { // chatTarget = GetTargetString(msg); if (GetTargetString(msg)) { msg = MessageCleaner(msg); ChatDataPackage cdp = new ChatDataPackage(); cdp.ChatDataPackages.Add(new ChatData { // SenderName = "Tais", SenderName = ((IPEndPoint)client.Client.LocalEndPoint).Address.ToString(), Message = msg, port = ((IPEndPoint)client.Client.LocalEndPoint).Port.ToString(), Target = chatTarget, PlayerName = clientName, typeColor = msColor }); byte[] data = TCPHelper.MessageBytes(cdp); client.GetStream().Write(data, 0, data.Length); Debug.Log("Sent: " + msg); } }
public void SendWhisper(string whisperName, ChatServerClient client) { if (tickMessages.ChatDataPackages.Count > 0) { //DEBUG if (chatGUI != null) { foreach (var item in tickMessages.ChatDataPackages) { chatGUI.chatHistorie.Add(item.PlayerName + " : " + item.port + " : " + item.Message + " : to: " + item.Target); } } byte[] mes = TCPHelper.MessageBytes(tickMessages); //skal finde playeren man whisper for (int i = 0; i < Clients.Count; i++) { if (Clients[i].clientName == whisperName) { Clients[i].SendToClient(mes); client.SendToClient(mes); } } } }
public void SendTokenToServer() { byte[] tokenData = TCPHelper.MessageBytes(token); TcpClient client = new TcpClient(Globals.MIDDLEWARE_IP, Globals.TOKENSYSTEM_PORT); client.GetStream().Write(tokenData, 0, tokenData.Length); string validateRequest = ((int)MessageType.Validate).ToString() + Server.MESSAGE_TYPE_INDICATOR + token; Message(validateRequest); }
public static void Disconnect(ServerClient disconnectedClient) { //Session manager - UNTESTED try { UserSession ses = new UserSession() { UserID = disconnectedClient.clientName, InGame = false, Request = SessionRequest.SetStatus }; byte[] data = TCPHelper.MessageBytes(ses); Server.SessionClient.GetStream().Write(data, 0, data.Length); } catch { } ServerActor disconnectedActor = null; foreach (ServerActor actor in Players) { if (actor.Client == disconnectedClient) { disconnectedActor = actor; SendDisconnectNotification(disconnectedActor.PlayerID); } } if (disconnectedActor != null) { //Gem spillerens state List <PlayerDataModel> saveStates = new List <PlayerDataModel>(); saveStates.Add(new PlayerDataModel() { PlayerDataRequest = PlayerDataRequest.Update, Online = false, PositionX = disconnectedActor.startingX, PositionY = disconnectedActor.startingY, UserID = disconnectedActor.Client.clientName, ResponseExpected = false }); byte[] data = TCPHelper.MessageBytesNewton(saveStates); databaseClient.GetStream().Write(data, 0, data.Length); //Fjern fra spillet MapGrid.grid[disconnectedActor.startingX, disconnectedActor.startingY].GetComponent <Cell>().UnoccupyCell(); ChangedCells.Add(Server.MapGrid.grid[disconnectedActor.startingX, disconnectedActor.startingY].GetComponent <Cell>(), 0); Players.Remove(disconnectedActor); GameObject.Destroy(disconnectedActor.gameObject); Clients.Remove(disconnectedClient); } }
// leave group public void LeaveGroup(string groupName, ChatServerClient client) { for (int i = 0; i < ChatServer.groups.Count; i++) { if (ChatServer.groups[i].GroupName == groupName) { ChatServer.groups[i].Members.Remove(client); var dasGroup = ChatServer.groups[i]; var mes = TCPHelper.MessageBytes(ChatServer.groups[i]); for (int y = 0; y < dasGroup.Members.Count; y++) { dasGroup.Members[i].SendToClient(mes); } } } }
private void ClientConnected(uint playerID, Vector2 playerPos) { DataCollectionPackage package = new DataCollectionPackage(); PositionDataPackage pData = new PositionDataPackage() { PlayerName = clientName, PlayerID = playerID, Position = playerPos }; package.PositionDataPackages.Add(pData); //Første package er mappens dimensioner GridDataPackage gData = new GridDataPackage() { X = Server.MapGrid.gridWidth, Y = Server.MapGrid.gridHeigth }; package.GridDataPackages.Add(gData); MessageType msgType = MessageType.Connect; string jsonPackage = JsonUtility.ToJson(package); string msg = ((int)msgType).ToString(); msg += Server.MESSAGE_TYPE_INDICATOR + jsonPackage; byte[] byteData = System.Text.Encoding.ASCII.GetBytes(msg); byte[] totalPackage = Server.AddSizeHeaderToPackage(byteData); SendToClient(totalPackage); try { UserSession ses = new UserSession() { UserID = clientName, InGame = true, Request = SessionRequest.SetStatus }; byte[] data = TCPHelper.MessageBytes(ses); Server.SessionClient.GetStream().Write(data, 0, data.Length); } catch { } }
public void SendToAll() { if (tickMessages.ChatDataPackages.Count > 0) { //DEBUG if (chatGUI != null) { foreach (var item in tickMessages.ChatDataPackages) { chatGUI.chatHistorie.Add(item.PlayerName + " : " + item.port + " : " + item.Message); } } // DEBUG end byte[] mes = TCPHelper.MessageBytes(tickMessages); for (int i = 0; i < Clients.Count; i++) { Clients[i].SendToClient(mes); chatGUI.chatHistorie.Add(Clients[i].clientName); } } }
public bool ValidateToken(string token) { byte[] tokenData = TCPHelper.MessageBytes(token); TcpClient client = new TcpClient(Globals.MIDDLEWARE_IP, Globals.TOKENSYSTEM_PORT); //TcpClient client = new TcpClient("192.168.87.107", GlobalVariables.TOKENSYSTEM_PORT); client.GetStream().Write(tokenData, 0, tokenData.Length); //Await response from TokenSystem bool done = false; while (!done) { if (client.GetStream().DataAvailable) { Debug.Log("incoming response!"); string response = TCPHelper.ReadStreamOnce(client.GetStream()); HttpStatusCode responseCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), response); if (responseCode == HttpStatusCode.OK) { Debug.Log("VALID"); done = true; return(true); } else { Debug.Log("INVALID"); done = true; return(false); } } } return(false); }