SHARE
TWEET

Everybody Edits Lobby - Connect to lobby

capasha Oct 23rd, 2018 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using PlayerIOClient;
  7. namespace LobbyConnection
  8. {
  9.  
  10.     class Program
  11.     {
  12.         public static Client client_;
  13.         static void Main(string[] args)
  14.         {
  15.             //Here do we login with our login data. This is only for EE logins and not Kongregate and linked accounts.
  16.             //If you choose to login as guest then you need to change roomtype in tryLobbyConnect.
  17.             PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "YourUsernameOrEmail", "YourPassword", null, (Client client) =>
  18.             {
  19.                 client_ = client;
  20.                 Console.WriteLine("Logged in");
  21.  
  22.                 //Here do we send our ConnectionUserid and a Random string with length of 5 characters.
  23.                 //It's needed to even connect to lobby.
  24.                 tryLobbyConnect(string.Format("{0}_{1}", client.ConnectUserId, RandomString(5)));
  25.  
  26.             }, (PlayerIOError error) => { Console.WriteLine($"Login Error: {error.Message}"); });
  27.             Console.Read();
  28.         }
  29.         //Create a connection to Lobby and with your id (UserID_RandomString)
  30.         public static void tryLobbyConnect(string id)
  31.         {
  32.             if (client_ != null)
  33.             {
  34.                 client_.Multiplayer.CreateJoinRoom(id, $"Lobby{client_.BigDB.Load("config", "config")["version"]}", true, null, null, lobbyConnected, (PlayerIOError error) => { tryLobbyConnect(id); });
  35.  
  36.             }
  37.         }
  38.         public static void lobbyConnected(Connection con)
  39.         {
  40.             con.OnMessage += (s, m) =>
  41.             {
  42.                
  43.                 switch (m.Type)
  44.                 {
  45.                     case "LobbyTo":
  46.                        /*
  47.                           Message 1 is the current id that get generated for you.
  48.                           It will look like UserID_RandomString.
  49.                           You need to join the lobby 1 more time with the generated id for you.
  50.                           Before you can send connection messages to lobby.
  51.                        */
  52.                         tryLobbyConnect(m.GetString(1));
  53.                         break;
  54.  
  55.                         //When connected to lobby you get this message.
  56.                     case "connectioncomplete":
  57.                         //Send a connection to the Lobby.
  58.                         break;
  59.                     /*
  60.                    case "theReceivedData":
  61.                            Here do you get the received data that you requested for. (Sent message)
  62.                         break;
  63.                     */
  64.                 }
  65.             };
  66.         }
  67.         //Generate a random string which contains lowercase and uppercase and numeric characters.
  68.         public static string RandomString(int length)
  69.         {
  70.             const string chars = "abcdefghijlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  71.             return new string(Enumerable.Repeat(chars, length)
  72.               .Select(s => s[new Random().Next(s.Length)]).ToArray());
  73.         }
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top