Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Net.Sockets;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string strFind1 = "Press enter to start the game";
- const string strFind2 = "Make your move. Type the number of the field you want to set! (1-9)\n\nField: ";
- const string strFind3 = "Press enter to start again";
- const string strFind4 = "Congratulations you won!";
- const string strFind5 = "Congratulations you won! 100/100";
- const int gridSize = 144;
- TcpClient tcpClient = new TcpClient();
- tcpClient.Connect("challenges.hackvent.hacking-lab.com", 1037);
- NetworkStream networkStream = tcpClient.GetStream();
- StreamReader clientStreamReader = new StreamReader(networkStream);
- string readstring = "";
- while (true) {
- int readChar = clientStreamReader.Read();
- if (readChar != -1) {
- readstring += Convert.ToChar(readChar);
- if (readstring.Length >= strFind1.Length) {
- if (readstring.Substring(readstring.Length - strFind1.Length) == strFind1) {
- readstring = "";
- byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes("\n");
- networkStream.Write(bytesToSend, 0, bytesToSend.Length);
- }
- }
- if (readstring.Length >= strFind2.Length) {
- if (readstring.Substring(readstring.Length - strFind2.Length) == strFind2) {
- string grid = readstring.Substring(1, readstring.Length - strFind2.Length - 1).Substring(readstring.Substring(1, readstring.Length - strFind2.Length - 1).Length - gridSize);
- grid = grid.Replace(" ", "");
- grid = grid.Replace("|", "");
- grid = grid.Replace("-", "");
- grid = grid.Replace("\n", "");
- readstring = "";
- string send = "";
- if (grid == "*********") send = "1";
- if (grid == "X***O****") send = "9";
- if (grid == "X*O*O***X") send = "7";
- if (grid == "X*O*O*XOX") send = "4";
- if (grid == "XOO*O*X*X") send = "8";
- if (grid == "XO*******") send = "8";
- if (grid == "XOO****X*") send = "7";
- if (grid == "XO**O***X") send = "8";
- if (grid == "XO**O*OXX") send = "3";
- if (grid == "XO**O**X*") send = "7";
- if (grid == "XO**O*XXO") send = "4";
- if (grid == "XOX*OOOXX") send = "4";
- if (grid == "XOO*O**XX") send = "7";
- if (grid == "XOO*O*XX*") send = "9";
- if (grid == "XOXOO*OXX") send = "6";
- if (grid == "XOO***XXO") send = "4";
- if (send == "")
- throw new Exception("not handled combination!");
- byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(send + "\n");
- networkStream.Write(bytesToSend, 0, bytesToSend.Length);
- }
- }
- if (readstring.Length >= strFind3.Length) {
- if (readstring.Substring(readstring.Length - strFind3.Length) == strFind3) {
- int pos1 = readstring.IndexOf(strFind4);
- if (pos1 >= 0) {
- int pos2 = readstring.IndexOf("\n", pos1);
- string found = readstring.Substring(pos1, pos2 - pos1);
- if (found != strFind5)
- Console.WriteLine(found);
- else {
- Console.WriteLine(readstring.Substring(pos1));
- break;
- }
- }
- byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes("\n");
- networkStream.Write(bytesToSend, 0, bytesToSend.Length);
- readstring = "";
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment