/** * Send the dungeon message through the socket to the server * @param Message the message to send */ private void SendDungeonMessage(String Message) { DungeonCommand dungMsg = new DungeonCommand(); dungMsg.command = Message; MemoryStream outStream = dungMsg.WriteData(Salt); try { clientSocket.Send(outStream.ToArray()); } catch { } }
/** * Main thread for receiving and incoming client buffers. */ static void ReceiveClientProcess(Object o) { //initialise varliable bool bQuit = false; Socket chatClient = (Socket)o; bool LoggedIn = false; bool ShouldEncrypt = false; //init a new player, might not be used, just easier to have all the varilables //in one object Player player = new Player(chatClient); //Stay stuck in the log in squence until the connection drops or they successfuly login while (!LoggedIn && bQuit == false) { LoggedIn = LoginSequence(ref player, ref bQuit, ref ShouldEncrypt); } //if they exited the login sequence because they quite, return function if (bQuit == true) { return; } //Send the start up stuff needed small delays to give the client time to catchup RequestQueue.Enqueue(() => AddNewPlayer(player)); Thread.Sleep(200); RequestQueue.Enqueue(() => DungeonAction("look", player)); Thread.Sleep(200); RequestQueue.Enqueue(() => SendDungeonInfo(player)); Thread.Sleep(200); RequestQueue.Enqueue(() => SendLocations()); //main process loop while (bQuit == false) { try { byte[] buffer = new byte[4096]; int result; result = chatClient.Receive(buffer); if (result > 0) { Msg m = Msg.DecodeStream(buffer, player.Salt, ShouldEncrypt); if (m != null) { switch (m.mID) { case DungeonCommand.ID: { DungeonCommand dungMsg = (DungeonCommand)m; RequestQueue.Enqueue(() => DungeonAction(dungMsg.command, player)); } break; //sometimes the map info does work quite right this is here if that happens //the client side will request a new one case MapLayout.ID: RequestQueue.Enqueue(() => SendDungeonInfo(player)); break; default: break; } } } else { // No messages to see here! } } catch (Exception) { //lost client, add a remove from queue call print to console bQuit = true; String output = "Lost client: " + player.PlayerName; Console.WriteLine(output); RequestQueue.Enqueue(() => RemoveClientByPlayer(player)); } } }