public void UpdateChannel(ref LongbowInstanceData Data, ref LongbowSessionData Session) { uCursorLeft = Console.CursorLeft; uCursorTop = Console.CursorTop; bool ReloadChannel = false; //int thingy; WebClient Client = new WebClient(); LongbowServer Server = new LongbowServer(); while (true) { Thread.Sleep(5000); //thingy = Data.ChannelBuffer.Count() - 2; for (int i = 0; i < Data.ChannelBuffer.Count; i++) { if (!ReloadChannel) { Tools.DrawChat(Data.ChannelBuffer, Data.TemporaryBuffer); Tools.DrawInput(ref Data); ReloadChannel = true; break; } if (Data.ChannelBuffer.Count > Data.ChannelBuffer_Last.Count) { Tools.DrawChat(Data.ChannelBuffer, Data.TemporaryBuffer); Tools.DrawInput(ref Data); break; } if (Data.ChannelBuffer[i] != Data.ChannelBuffer_Last[i]) { Tools.DrawChat(Data.ChannelBuffer, Data.TemporaryBuffer); Tools.DrawInput(ref Data); break; } } //Console.WriteLine("\n\n"+Data.ChannelBuffer[thingy]); Server.GetNewPosts(Data, Session, Client); } }
public static void Main(string[] args) { string username = ""; bool askusername = false; LongbowToolkit Tools = new LongbowToolkit(); LongbowInstanceData Data = new LongbowInstanceData(); LongbowSessionData Session = new LongbowSessionData(); LongbowServer Server = new LongbowServer(); Console.WriteLine(LongbowCore.init_text); WebClient fetch = new WebClient(); if (args.Length > 0) { Session.Login = args[0]; if (Session.Login.Length < 3) { Console.WriteLine("Invalid username. Please try again."); askusername = true; } } else { askusername = true; } if (askusername) { Console.WriteLine("Username:"******"Attempting to log in as " + Session.Login + "...\nPassword: "******"password="******"&username="******"application/x-www-form-urlencoded"; //define our variables string data = string.Empty; string games_count = string.Empty; string lberror = string.Empty; string[] game_entry = new string[2]; int gameselection_int = 0; int chat_slice = 0; List <string> games_names = new List <string>(); List <string> games_ids = new List <string>(); string channel_line = string.Empty; //end variables data = fetch.UploadString(api_url, parameters); XmlDocument xml = new XmlDocument(); try { xml.LoadXml(data); } catch (Exception Ex) { Console.WriteLine("An unexpected response was received from the server. Is Longbow-CLI up to date?\n\nResponse: " + data); Environment.Exit(0); } XmlNodeList xnList = xml.SelectNodes("/root/error"); foreach (XmlNode xn in xnList) { lberror = xn["text"].InnerText; if (lberror.Length > 0) { Console.WriteLine(lberror); Environment.Exit(0); } } //Console.WriteLine(data); xnList = xml.SelectNodes("/root/session"); foreach (XmlNode xn in xnList) { Session.SessionID = xn["luxSession"].InnerText; Session.Login = xn["luxLogin"].InnerText; } xnList = xml.SelectNodes("/root"); foreach (XmlNode xn in xnList) { games_count = xn["games_count"].InnerText; } xnList = xml.SelectNodes("/root/games/item"); foreach (XmlNode xn in xnList) { game_entry[0] = xn["gameid"].InnerText; game_entry[1] = xn["gamename"].InnerText; games_ids.Add(game_entry[0]); games_names.Add(game_entry[1]); } //XDocument doc = XDocument.Parse(data); //var session = doc.Root.Elements("session").Elements("luxSession").Select(element=>element.Value).ToList(); //var gamescount = doc.Root.Elements("games_count").Select(element=>element.Value).ToList(); //foreach(string value in gamescount){ Console.WriteLine(value); } //foreach(string value in session){ Console.WriteLine(value); } Console.WriteLine("\n\n\n\n\n\n\n\n\nLogged in as: {1} Games total: {0}", games_count, Session.Login); Tools.DrawDivider(); for (int i = 0; i < games_ids.Count(); i++) { Console.WriteLine("> " + (i + 1) + " (ID: "+ games_ids[i] + ") " + Tools.StripSlashes(games_names[i])); } Console.WriteLine("\n\nPlease enter the number (not ID) of the game you wish to join."); string gameselection = ""; bool ChoseGame = false; while (!ChoseGame) { gameselection = Console.ReadLine(); try { gameselection_int = Convert.ToInt32(gameselection) - 1; //fencepost! } catch (FormatException e) { Console.WriteLine("That is not a number."); } finally { if (gameselection_int > games_ids.Count() || gameselection_int == -1) { Console.WriteLine("Not a valid game! Try again."); } else { ChoseGame = true; } } } Data.ChannelID = Convert.ToInt32(games_ids[gameselection_int]); Data.ChannelName = games_names[gameselection_int]; Console.WriteLine("Joining \"{0}\".\n", games_names[gameselection_int]); Tools.DrawDivider(); //being lazy and plunking down the connection code here again parameters = "session=" + Session.SessionID + "&username="******"&chatinit=" + games_ids[gameselection_int]; fetch.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; data = fetch.UploadString(api_url, parameters); //Console.WriteLine(api_url+"?"+parameters); //return; xml.LoadXml(data); xnList = xml.SelectNodes("/root/item"); string curtext = string.Empty; foreach (XmlNode xn in xnList) { if (xn["editedcontent"].InnerText.Length > 0) { curtext = xn["editedcontent"].InnerText; } else { curtext = xn["content"].InnerText; } Data.LastPost = xn["timestamp"].InnerText; channel_line = xn["username"].InnerText + ": " + Tools.StripSlashes(curtext); if (xn["band"].InnerText == "3") { channel_line = "(OOC) " + channel_line; } channel_line = HttpUtility.HtmlDecode(channel_line); Data.ChannelBuffer.Add(channel_line); } //render the screen manually the first time Tools.DrawChat(Data.ChannelBuffer, Data.TemporaryBuffer); Tools.DrawInput(ref Data); //MAIN LOOP BEGIN bool loop = true; LongbowWorkerThread Worker = new LongbowWorkerThread(); //Thread w = new Thread(Worker.UpdateChannel); //w.Start(Data.ChannelBuffer); ThreadPool.QueueUserWorkItem(o => Worker.UpdateChannel(ref Data, ref Session)); ThreadPool.QueueUserWorkItem(o => Worker.ProcessPostQueue(ref Data, ref Session)); ConsoleKeyInfo inText; int uCursorTop; int uCursorLeft; int ExcerptSize; string LeftBuffer; string RightBuffer; Data.vCursorPos = 2; Data.vBufferPos = 0; Data.ChatPrev.Add(""); //sConsole.Write("> "+Data.ChatCurrent+" "); Console.SetCursorPosition(2, Console.CursorTop); while (loop) { uCursorLeft = Console.CursorLeft; uCursorTop = Console.CursorTop; inText = Console.ReadKey(); if (inText.Key == ConsoleKey.Backspace) { if (uCursorLeft > 2) { Console.SetCursorPosition(uCursorLeft - 1, uCursorTop); LeftBuffer = Data.ChatCurrent.Substring(0, Data.vCursorPos - 2); RightBuffer = Data.ChatCurrent.Substring(Data.vCursorPos - 2); Data.ChatCurrent = LeftBuffer.Substring(0, LeftBuffer.Length - 1) + RightBuffer; Console.Write(" " + uCursorLeft); Data.vCursorPos--; } Tools.DrawInput(ref Data); } else if (inText.Key == ConsoleKey.Enter) { Console.WriteLine(Session.Login + ": " + Data.ChatCurrent); Data.TemporaryBuffer.Add(Session.Login + ": " + Data.ChatCurrent); Tools.QueueNewPost(ref Data, Data.ChatCurrent); Data.ChatPrev.Add(Data.ChatCurrent); Data.ChatCurrent = ""; if (Data.ChatPrev[0].Length > 7) { Data.ChatPrev.Add(Data.ChatPrev[0]); } Data.ChatPrev[0] = ""; Data.vCursorPos = 2; Data.vBufferPos = 0; ThreadPool.QueueUserWorkItem(o => Worker.UpdateChannel(ref Data, ref Session)); Tools.DrawChat(Data.ChannelBuffer, Data.TemporaryBuffer); Tools.DrawInput(ref Data); } else if (inText.Key == ConsoleKey.LeftArrow || inText.Key == ConsoleKey.RightArrow) { if (inText.Key == ConsoleKey.LeftArrow) { if (Data.vCursorPos > 2) { Console.SetCursorPosition(Console.CursorLeft - 1, uCursorTop); Data.vCursorPos--; } Data.vCursorVelocity = -1; } else { if (Data.vCursorPos < Data.ChatCurrent.Length + 2) { Console.SetCursorPosition(uCursorLeft + 2, uCursorTop); Data.vCursorPos++; } Data.vCursorVelocity = 1; } Tools.DrawInput(ref Data); } else if (inText.Key == ConsoleKey.UpArrow || inText.Key == ConsoleKey.DownArrow) { Data.vCursorPos = 2; if (inText.Key == ConsoleKey.UpArrow) { if (Data.vBufferPos == 0) { Data.ChatPrev[0] = Data.ChatCurrent; } if (Data.vBufferPos < Data.ChatPrev.Count - 1) { Data.vBufferPos++; Data.ChatCurrent = Data.ChatPrev[Data.ChatPrev.Count - Data.vBufferPos]; } } else { if (Data.vBufferPos > 0) { Data.vBufferPos--; Data.ChatCurrent = Data.ChatPrev[Data.ChatPrev.Count - Data.vBufferPos - 1]; } else if (Data.vBufferPos == 0) { Data.ChatCurrent = Data.ChatPrev[0]; } } Data.vCursorPos = Data.ChatCurrent.Length + 2; Tools.DrawInput(ref Data); } else //Process it as chantext input //Console.Write(inText.KeyChar); //Data.ChatCurrent = Data.ChatCurrent.Substring(0,Data.ChatCurrent.Length-1); { LeftBuffer = Data.ChatCurrent.Substring(0, Data.vCursorPos - 2); RightBuffer = Data.ChatCurrent.Substring(Data.vCursorPos - 2); Data.ChatCurrent = LeftBuffer + inText.KeyChar + RightBuffer; //Data.ChatCurrent = Data.ChatCurrent + inText.KeyChar; Data.vCursorPos++; Tools.DrawInput(ref Data); } } }