protected override Request CreateRequest() { LogDebug("Sending Login Request"); LoginRequest loginRequest = new LoginRequest() { Identity = player.IdentityInfo, ProcessLabel = player.ProcessLabel, ProcessType = ProcessInfo.ProcessType.Player }; player.ProcessInfo.Status = ProcessInfo.StatusCode.Initializing; return loginRequest; }
public void LoginRequest_TestEverything() { LoginRequest r1 = new LoginRequest(); Assert.IsNull(r1.Identity); IdentityInfo i1 = new IdentityInfo() { ANumber = "2375423", FirstName = "Tom", LastName = "Thompson", Alias = "Tommy" }; LoginRequest r2 = new LoginRequest() { ProcessType = ProcessInfo.ProcessType.Player, ProcessLabel = "Test Player", Identity = i1 }; Assert.AreEqual(ProcessInfo.ProcessType.Player, r2.ProcessType); Assert.AreEqual("Test Player", r2.ProcessLabel); Assert.IsNotNull(r2.Identity); Assert.AreEqual("2375423", r2.Identity.ANumber); Assert.AreEqual("Tom", r2.Identity.FirstName); Assert.AreEqual("Thompson", r2.Identity.LastName); Assert.AreEqual("Tommy", r2.Identity.Alias); byte[] bytes = r2.Encode(); Message m2 = Message.Decode(bytes); LoginRequest r3 = m2 as LoginRequest; Assert.AreEqual(r3.ProcessType, r2.ProcessType); Assert.AreEqual(r2.ProcessLabel, r3.ProcessLabel); Assert.IsNotNull(r3.Identity); Assert.AreEqual(r2.Identity.ANumber, r3.Identity.ANumber); Assert.AreEqual(r2.Identity.FirstName, r3.Identity.FirstName); Assert.AreEqual(r2.Identity.LastName, r3.Identity.LastName); Assert.AreEqual(r2.Identity.Alias, r3.Identity.Alias); }
public void doWork() { ProcessInfo myPI=new ProcessInfo(); //create login message IdentityInfo ii= getIdentity(ConfigurationManager.AppSettings["myFirstName"], ConfigurationManager.AppSettings["myLastName"], ConfigurationManager.AppSettings["myANumber"], ConfigurationManager.AppSettings["myAlias"]); LoginRequest lr= new LoginRequest() { ProcessType = ProcessInfo.ProcessType.Player, ProcessLabel = "Chauffy's Player", Identity = ii }; byte[] loginRequestMessage = lr.Encode(); //end create login message //setup connection IPEndPoint loginTarget = getEndpoint(ConfigurationManager.AppSettings["registryIP"], ConfigurationManager.AppSettings["registryPort"]); Program.socket.Connect(loginTarget); //end setup connection //send login request Program.socket.Send(loginRequestMessage, loginRequestMessage.Length); loginTarget = getEndpoint(ConfigurationManager.AppSettings["registryIP"], ConfigurationManager.AppSettings["registryPort"]); //end send login request //listen for login reply var receivedData = Program.socket.Receive(ref loginTarget); Message lResponse = Message.Decode(receivedData); LoginReply myLoginReply = lResponse as LoginReply; if (myLoginReply.Success) { myPI = myLoginReply.ProcessInfo; Console.WriteLine("Succeessful Login. \nProcess ID: " + myPI.ProcessId + " \nLabel: " + myPI.Label); Console.WriteLine("Process Info: " + myLoginReply.ProcessInfo + " \nNote: " + myLoginReply.Note); //Start Ear Thread Ear ear = new Ear(); Thread myEarThread = new Thread(new ThreadStart(ear.doWork)); myEarThread.Start(); //end Start Ear Thread } else { Console.WriteLine("Login Failed."); } //end listen for login reply //create gamelist request message GameListRequest glr = new GameListRequest() { StatusFilter = 111111 }; byte[] gameListRequestMessage = glr.Encode(); //end create gamelist request message //send gamelist request Program.socket.Send(gameListRequestMessage, gameListRequestMessage.Length); //end send gamelist request //listen for gamelist reply var glData = Program.socket.Receive(ref loginTarget); Message glResponse = Message.Decode(glData); GameListReply myGLReply = glResponse as GameListReply; if (myGLReply.Success) { GameInfo[] myGameList = myGLReply.GameInfo; Console.WriteLine("Succeessful Game List Request."); Console.WriteLine("There are " + myGameList.Length + " available games."); for (int i = 0; i < myGameList.Length; i++) { Console.WriteLine("Game at ID: " + myGameList[i].GameId+ " status is: "+ myGameList[i].Status); } //create gamejoin request JoinGameRequest jgr; for (int i = 0; i < myGameList.Length; i++) { if (myGameList[i].Status == GameInfo.StatusCode.Available|| myGameList[i].Status == GameInfo.StatusCode.InProgress) { jgr = new JoinGameRequest() { GameId = myGameList[0].GameId, Player = myPI, }; IPEndPoint gameTarget = getEndpoint(myGameList[0].GameManager.EndPoint.Host, myGameList[0].GameManager.EndPoint.IPEndPoint.Port.ToString()); Program.socket.Connect(gameTarget); byte[] gameJoinRequestMessage = jgr.Encode(); //end create gamejoin request //send gamejoin request Program.socket.Send(gameJoinRequestMessage, gameJoinRequestMessage.Length); //end send gamejoin request //receive gamejoin reply var gjData = Program.socket.Receive(ref loginTarget); Message gjResponse = Message.Decode(gjData); JoinGameReply myGJResply = gjResponse as JoinGameReply; if (myGJResply.Success) { Console.WriteLine("Connected to Game at id: "+myGameList[i].GameId); break; } else Console.WriteLine("Failed to connect to Game."); } else Console.WriteLine("Game Not Available."); } //Console.WriteLine("No Available Games."); } else { Console.WriteLine("Game List Request Failed."); } //end listen for gamelist reply return; }