Advertisement
Guest User

Untitled

a guest
Jan 28th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using PlayerIOClient;
  6. using System.Text.RegularExpressions;
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static Connection con;
  12.         static void Main(string[] args)
  13.         {
  14.             while (true)
  15.             {
  16.                 var rline = Console.ReadLine();
  17.                 if (rline.Substring(0, 2) == "-c")
  18.                 {
  19.                     Console1ParamCheck(rline);
  20.                 }
  21.                 else if (rline == "-h")
  22.                 {
  23.                     Console.WriteLine("\t\t ### HELP ### \n");
  24.                     Console.WriteLine("\t-c Email Password RoomID - Use this to login and join a room.");
  25.                     Console.WriteLine("\t-rs - Respawn the bot.");
  26.                 }
  27.                 else if (rline == "-rs")
  28.                 {
  29.                     try
  30.                     {
  31.                         if (con.Connected)
  32.                         {
  33.                             con.Send("say", "/reset");
  34.                         }
  35.                     }
  36.                     catch
  37.                     {
  38.                         Console.WriteLine("Error: You have to be connected to use this command");
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.         static void connect(string u, string p, string r)
  44.         {
  45.             PlayerIO.QuickConnect.SimpleConnect("blocking-blocks-u4zmkxjugu0ap8xqbymw", u, p,
  46.                 delegate(Client c)
  47.                 {
  48.                     Console.WriteLine("Logged on successfully");
  49.                     try
  50.                     {
  51.                         con = c.Multiplayer.JoinRoom(r, null);
  52.                         Console.WriteLine("Connected to room");
  53.                         con.Send("init");
  54.                         con.Send("init2");
  55.                         con.OnMessage += new MessageReceivedEventHandler(con_OnMessage);
  56.                     }
  57.                     catch (PlayerIOError error)
  58.                     {
  59.                         Console.WriteLine("Error: " + error);
  60.                     }
  61.                 },
  62.                 delegate(PlayerIOError error)
  63.                 {
  64.                     Console.WriteLine("Error: " + error);
  65.                 });
  66.         }
  67.                 static void Console1ParamCheck(string rline)
  68.         {
  69.             if (Regex.Matches(rline, @"[ ]+").Count == 3)
  70.             {
  71.                 string[] words = rline.Split(' ');
  72.                 if (words[1].Contains("@"))
  73.                 {
  74.                     if (words[2].Length >= 4)
  75.                     {
  76.                         if (Regex.IsMatch(words[3], "(PW|BW)+[A-f0-9_-]{3,13}", RegexOptions.IgnoreCase))
  77.                         {
  78.                             Console.Clear();
  79.                             connect(words[1], words[2], words[3]);
  80.                         }
  81.                         else
  82.                         {
  83.                             Console.Clear();
  84.                             Console.WriteLine("The roomID is incorrect.");
  85.                         }
  86.                     }
  87.                     else
  88.                     {
  89.                         Console.Clear();
  90.                         Console.WriteLine("The password is too short.");
  91.                     }
  92.                 }
  93.                 else
  94.                 {
  95.                     Console.Clear();
  96.                     Console.WriteLine("The E-mail is incorrect.");
  97.                 }
  98.             }
  99.             else
  100.             {
  101.                 Console.Clear();
  102.                 Console.WriteLine("Unknown parameters.\nUsage: -c email password roomid");
  103.             }
  104.         }
  105.         static void con_OnMessage(object sender, PlayerIOClient.Message m)
  106.         {
  107.             switch (m.Type)
  108.             {
  109.                 case "init":
  110.                     Console.WriteLine("Connected to: " + m.GetString(1));
  111.                     break;
  112.                 case "say":
  113.                     if (m.GetString(1).ToLower().StartsWith("hi"))
  114.                     {
  115.                         con.Send("say", "Hello!");
  116.                     }
  117.                     else if (m.GetString(1).ToLower().StartsWith("hello"))
  118.                     {
  119.                         con.Send("say", "Hello!");
  120.                     }
  121.                     else if (m.GetString(1).ToLower().EndsWith("?"))
  122.                     {
  123.                         Random rnd = new Random();
  124.                         var rand = rnd.Next(1,4);
  125.                         switch (rand)
  126.                         {
  127.                             case 1:
  128.                                 con.Send("say", "Chuck Norris");
  129.                                 break;
  130.                             case 2:
  131.                                 con.Send("say", "Depends. What flavor napkin do you like?");
  132.                                 break;
  133.                             case 3:
  134.                                 con.Send("say", "You don't want to know...");
  135.                                 break;
  136.                         }
  137.                     }
  138.                     break;
  139.             }
  140.             }
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement