Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.21 KB | None | 0 0
  1. {
  2.             TcpClient tcpClient = (TcpClient)client;
  3.             MyClient myClient = new MyClient(tcpClient);
  4.             String fromClient;
  5.             commands = new mudcommands();
  6.             Console.WriteLine(myClient.IPAddress + " has connected to the server.\n");
  7.             bool isConnected = false;
  8.             String input = "";
  9.             string username = "";
  10.            
  11.            
  12.             String password = "";
  13.  
  14.             while (input.Length == 0 && myClient.IsAlive())
  15.             {
  16.                 myClient.SendToClient("Welcome to The Clone Wars Era, we are currently not open for mudding at this time, If you are an admin or a builder, please type in your username and password, else please try again another time.\r\n");
  17.                 myClient.SendToClient("Username: ");
  18.                 if (!myClient.IsAlive())
  19.                 {
  20.                     return;
  21.                 }
  22.                 input = myClient.toServer().Trim();
  23.                 DataTable Username = DBclass.GetInstance().DoSql("Select name from players where name='" + input + "'");
  24.                 try
  25.                 {
  26.                     username = Username.Rows[0].Field<string>("name");
  27.                 }
  28.                 catch (Exception )
  29.                 {
  30.                    
  31.                     throw;
  32.                 }
  33.                
  34.                 if (input.ToLower() == username)
  35.                 {  
  36.                     if (true)
  37.                     {
  38.                         myClient.SendToClient("Password: ");
  39.                         password = myClient.toServer().Trim();
  40.                         DataTable Password = DBclass.GetInstance().DoSql("Select Password from players where Password='" + password + "'");
  41.                         if (password == Password.Rows[0].Field<string>("Password").ToString())
  42.                         {
  43.                             lock (_newClientNumber)
  44.                             {
  45.                                 while (clientlist.ContainsValue(clientnumber))
  46.                                 {
  47.                                     clientnumber++;
  48.                                 }
  49.                                 clientlist.Add(myClient, clientnumber);
  50.                             }
  51.                             DataTable ID = DBclass.GetInstance().DoSql("Select ID from players where name='" + username + "'");
  52.                             myClient.playerID = ID.Rows[0].Field<int>("ID");
  53.                             int playerloc = players.getPlayerLocation(players.playerID(username));
  54.                             myClient.SendToClient("You are logged in under the username " + input);
  55.                             myClient.SendToClient("> ");
  56.                             isConnected = true;
  57.                             //commands.look();
  58.                         }
  59.                         else
  60.                         {
  61.                             myClient.SendToClient("Password failed: please try again.");
  62.                             tcpClient.Close();
  63.                         }
  64.                     }
  65.                 }
  66.                 else
  67.                 {
  68.                     myClient.SendToClient("Username failed, if you feel you have recieved this in error, please contact Joshua at Rpgdudester@hotmail.com ");
  69.                     tcpClient.Close();
  70.                 }
  71.             }
  72.  
  73.  
  74.             while (isConnected == true && myClient.IsAlive())
  75.             {
  76.                 fromClient = myClient.toServer().Trim();
  77.                 myClient.SendToClient(input + " > ");
  78.                 string[] split = fromClient.ToLower().Split(' ');
  79.                 switch (split[0])
  80.                 {
  81.                 case "say":
  82.                   foreach (MyClient sendto in clientlist.Keys)
  83.                     {
  84.                     sendto.SendToClient(input + " said " + fromClient.Remove(0, 4));
  85.                     }
  86.                     break;
  87.                 case "quit":
  88.                         myClient.SendToClient("You have left the Clone Wars and returned to a peasant's life.");
  89.                         isConnected = false;
  90.                         break;
  91.                
  92.                 //this area is for the movement commands, added in on 03/01/2010 by Jpb
  93.                 case "north":
  94.                         commands.Move(fromClient);
  95.                         break;
  96.                 case "south":
  97.                         commands.Move(fromClient);
  98.                         break;
  99.                 case "west":
  100.                         commands.Move(fromClient);
  101.                         break;
  102.                 case "east":
  103.                         commands.Move(fromClient);
  104.                         break;
  105.  
  106.                 case "test":
  107.                         myClient.SendToClient("This is a test for " + input);
  108.                         break;
  109.                 case "look":
  110.                         commands.look();
  111.                         break;
  112.                     default:
  113.                         myClient.SendToClient("What are you trying to do?");
  114.                         break;
  115.                 }
  116.             }
  117.             clientlist.Remove(myClient);
  118.             tcpClient.Close();
  119.             Console.WriteLine(myClient.IPAddress + " has logged out of the server.\n");
  120.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement