Advertisement
Guest User

main.cs

a guest
Aug 20th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. using System;
  2. using GruntXProductions.CoreLib.Networking;
  3.  
  4. namespace TcpClient
  5. {
  6. class MainClass
  7. {
  8. public static string ip;
  9. public static int port;
  10. public static string user;
  11. public static void Main(string[] args)
  12. {
  13. //Connect to Jacob Misirian as default
  14. ip = "65.26.244.200";
  15. port = 1013;
  16. Connect.ActuallyConnnect();
  17. WeDoneConnecting();
  18. }
  19. public static void WeDoneConnecting()
  20. {
  21.  
  22. try
  23. {
  24.  
  25. PacketPipeLine.RegisterPacket(typeof(MessagePacket));
  26. if (Connect.client.Connect())
  27. {
  28. //When the user connects get the nickname they want to use
  29. Console.Write("Nickname: ");
  30. user = Console.ReadLine();
  31.  
  32. Connect.client.SendPacket(new UserPacket(user));
  33.  
  34. //Display welcome message and tell user how to get help
  35. Console.Write("Welcome " + user + " to JacoChat Verison 1.1\nTo send out a message, type that message and press enter\nTo quit JacoChat properly, type quit and press enter. For a list of commands, type help\n");
  36.  
  37. //Send out message that this new user has joined
  38. Connect.client.SendPacket(new MessagePacket("User " + user, " has joined JacoChat"));
  39.  
  40.  
  41. while (true)
  42. {
  43. //Get input from the user
  44.  
  45. string message = Console.ReadLine();
  46.  
  47. //If the line is any of the commands then we should run those commands
  48. if (message == "quit")
  49. {
  50. Commands.quit();
  51. }
  52. else if (message == "help")
  53. {
  54. Commands.help();
  55. }
  56. else if (message == "nick")
  57. {
  58. //var arg = JacOS.rseperate(message, 5, (message.Length - 1));
  59. Commands.nick();
  60. }
  61. else if (message == "connect")
  62. {
  63. Commands.connect();
  64. }
  65. else
  66. {
  67. //If it's not any of those commands then just send out the message like normal
  68. Connect.client.SendPacket(new MessagePacket(user, message));
  69. }
  70.  
  71. }
  72. }
  73. else //This is for if we couldn't connect right
  74. {
  75. BackToPrompt:
  76.  
  77. //If it's Jacob Misirian's ip, we'll just call it default for simplicity
  78. if (MainClass.ip == "65.26.244.200")
  79. {
  80. MainClass.ip = "default";
  81. }
  82.  
  83. //Provide the error message and ask if the user wants to connect to a differant host
  84. JacOS.ColorWrite("We were not able to connect to the host " + MainClass.ip + "\nWould you like to connect to another IP? y/n: ", ConsoleColor.Red);
  85. string procede = Console.ReadLine();
  86.  
  87. //If the user's giving up, kill the application
  88. if (procede == "n")
  89. {
  90. Environment.Exit(0);
  91. }
  92. else if (procede == "y")
  93. {
  94. //Ask for the ip they wanna connect to, if they leave it blank it will connect to Jacob Misirian
  95. Console.Write("\nEnter your the new IP. To connect to Jacob Misirian leave it blank and press enter: ");
  96. MainClass.ip = Console.ReadLine();
  97. if (MainClass.ip == "")
  98. {
  99. //Jacob Misirian default
  100. MainClass.ip = "65.26.244.200";
  101. MainClass.port = 1013;
  102. }
  103. else
  104. {
  105. //Grap the custom port
  106. Console.Write("Enter the port for your custom host: ");
  107. MainClass.port = Convert.ToInt32(JacOS.ReadNum(0, 1000000, 1013));
  108. }
  109. //Try to connect again then go back to the top baby!
  110. Connect.ActuallyConnnect();
  111. MainClass.WeDoneConnecting();
  112. }
  113. else
  114. {
  115. //If they were dummies and didn't enter y or n, go back to the prompt asking them if they wanna try again or not
  116. goto BackToPrompt;
  117. }
  118. }
  119. }
  120. //IDK really
  121. catch (Exception e)
  122. {
  123. Console.WriteLine(e.ToString());
  124. Console.ReadLine();
  125. }
  126. }
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement