private void Login(byte[] msg) { //pull new player off connectingUsers on the server and instantiate them into the game //LoginMsg loginMsg = JsonUtility.FromJson<LoginMsg>(msg); LoginMsg loginMsg = new LoginMsg(msg); //Debug.Log(string.Format("In NetMan: {0}", loginMsg.playerType)); ClientData clientData = server.connecting[loginMsg.from]; clientData.playerType = loginMsg.playerType; clientData.personType = loginMsg.personType; //Debug.Log(string.Format("LOGIN FROM: {0}", loginMsg.from)); server.connecting.Remove(loginMsg.from); instantiatePlayerQ.Enqueue(clientData); }
//Listen for new connection so that they can be stored in the clients table public void ListenForConnections() { listen.Start(); TcpClient client; Socket socket; NetworkStream stream; IPAddress ipAddress; ClientData clientData; try { while (true) { //Debug.Log("Waiting on clients"); client = listen.AcceptTcpClient(); socket = client.Client; stream = client.GetStream(); ipAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address; clientData = new ClientData(idCount++, socket, stream, ipAddress); connecting.Add(clientData.id, clientData); //Debug.Log("Client Added"); connectionCount++; //This is where the login notification will go******************************* LoginMsg msg = new LoginMsg(clientData.id); Debug.Log(string.Format("In Server: {0}", msg.from)); byte[] message = msg.GetBytes(); stream.Write(message, 0, message.Length); threads.Add(new Thread(() => ReceiveMsg(clientData))); threads[threads.Count - 1].Start(); } } catch (SocketException exception) { //Debug.Log(String.Format("SocketException: {0}", exception.ToString())); listen.Stop(); } }