Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using GruntXProductions.CoreLib.Networking;
- namespace TcpClient
- {
- class MainClass
- {
- public static string ip;
- public static int port;
- public static string user;
- public static void Main(string[] args)
- {
- //Connect to Jacob Misirian as default
- ip = "65.26.244.200";
- port = 1013;
- Connect.ActuallyConnnect();
- WeDoneConnecting();
- }
- public static void WeDoneConnecting()
- {
- try
- {
- PacketPipeLine.RegisterPacket(typeof(MessagePacket));
- if (Connect.client.Connect())
- {
- //When the user connects get the nickname they want to use
- Console.Write("Nickname: ");
- user = Console.ReadLine();
- Connect.client.SendPacket(new UserPacket(user));
- //Display welcome message and tell user how to get help
- 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");
- //Send out message that this new user has joined
- Connect.client.SendPacket(new MessagePacket("User " + user, " has joined JacoChat"));
- while (true)
- {
- //Get input from the user
- string message = Console.ReadLine();
- //If the line is any of the commands then we should run those commands
- if (message == "quit")
- {
- Commands.quit();
- }
- else if (message == "help")
- {
- Commands.help();
- }
- else if (message == "nick")
- {
- //var arg = JacOS.rseperate(message, 5, (message.Length - 1));
- Commands.nick();
- }
- else if (message == "connect")
- {
- Commands.connect();
- }
- else
- {
- //If it's not any of those commands then just send out the message like normal
- Connect.client.SendPacket(new MessagePacket(user, message));
- }
- }
- }
- else //This is for if we couldn't connect right
- {
- BackToPrompt:
- //If it's Jacob Misirian's ip, we'll just call it default for simplicity
- if (MainClass.ip == "65.26.244.200")
- {
- MainClass.ip = "default";
- }
- //Provide the error message and ask if the user wants to connect to a differant host
- 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);
- string procede = Console.ReadLine();
- //If the user's giving up, kill the application
- if (procede == "n")
- {
- Environment.Exit(0);
- }
- else if (procede == "y")
- {
- //Ask for the ip they wanna connect to, if they leave it blank it will connect to Jacob Misirian
- Console.Write("\nEnter your the new IP. To connect to Jacob Misirian leave it blank and press enter: ");
- MainClass.ip = Console.ReadLine();
- if (MainClass.ip == "")
- {
- //Jacob Misirian default
- MainClass.ip = "65.26.244.200";
- MainClass.port = 1013;
- }
- else
- {
- //Grap the custom port
- Console.Write("Enter the port for your custom host: ");
- MainClass.port = Convert.ToInt32(JacOS.ReadNum(0, 1000000, 1013));
- }
- //Try to connect again then go back to the top baby!
- Connect.ActuallyConnnect();
- MainClass.WeDoneConnecting();
- }
- else
- {
- //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
- goto BackToPrompt;
- }
- }
- }
- //IDK really
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement