Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TwitchChatter;
  5.  
  6. public class networking : MonoBehaviour
  7. {
  8.     public SortedList<string, sync> players = new SortedList<string, sync>();
  9.     public SortedList<string, sync> netobjs = new SortedList<string, sync>();
  10.  
  11.     //3 channels - chat/data/world (has start and stop gaps and requests)
  12.  
  13.     public string chatchan = "NeverdauntRL", datachan = "NeverdauntRLdata", worldchan = "NeverdauntRLworld";
  14.  
  15.     void Start()
  16.     {
  17.         // Add a chat listener.
  18.         TwitchChatClient.singleton.AddChatListener(OnChatMessage);
  19.  
  20.         // Set your credentials. If you're not planning on sending messages,
  21.         //// you can remove these lines.
  22.  
  23.         togsave.isOn = PlayerPrefs.GetInt("save", 1) == 1;
  24.         //// Join some channels.
  25.         //TwitchChatClient.singleton.JoinChannel("SomeChannelName");
  26.         if (togsave.isOn)
  27.         {
  28.             oauth.text = PlayerPrefs.GetString("oauth", "");
  29.             username.text = PlayerPrefs.GetString("user", "");
  30.         }
  31.     }
  32.  
  33.     public UnityEngine.UI.InputField infi;
  34.     public GameObject loginpan;
  35.     public UnityEngine.UI.InputField username, oauth;
  36.     public UnityEngine.UI.Toggle togsave;
  37.     public void Login()
  38.     {
  39.         if (togsave.isOn)
  40.         {
  41.             PlayerPrefs.SetString("user", username.text);
  42.             PlayerPrefs.SetString("oauth", oauth.text);
  43.             PlayerPrefs.SetInt("save", 1);
  44.         }
  45.         else
  46.         {
  47.             PlayerPrefs.SetString("user", "");
  48.             PlayerPrefs.SetString("oauth", "");
  49.             PlayerPrefs.SetInt("save", 0);
  50.  
  51.         }
  52.  
  53.         PlayerPrefs.Save();
  54.  
  55.         loginpan.SetActive(false);
  56.         TwitchChatClient.singleton.userName = username.text;
  57.         TwitchChatClient.singleton.oAuthPassword = oauth.text;
  58.         infi.Select();
  59.         infi.ActivateInputField();
  60.  
  61.         TwitchChatClient.singleton.JoinChannel(chatchan);
  62.  
  63.         //   TwitchChatClient.singleton.JoinChannel(worldchan);
  64.  
  65.         //  TwitchChatClient.singleton.JoinChannel(datachan);
  66.  
  67.         // If you set your credentials and you'd like to receive whispers,
  68.         //  call EnableWhispers to allow for sending/receiving whispers.
  69.         // TwitchChatClient.singleton.EnableWhispers();
  70.  
  71.         // Then, add any whisper listeners you'd like.
  72.         //   TwitchChatClient.singleton.AddWhisperListener(OnWhisper);
  73.     }
  74.  
  75.     //void Chat()
  76.     //{
  77.     //    // If you set your credentials, send some messages.
  78.     //    TwitchChatClient.singleton.SendMessage("SomeChannelName", "Kappa Message sent by Twitch Chatter! Kappa");
  79.     //}
  80.  
  81.     //void Whisper()
  82.     //{
  83.     //    // If you set your credentials and enabled whispers with EnableWhispers(), send some whispers.
  84.     //    TwitchChatClient.singleton.SendWhisper("SomeUserName", "PogChamp Sending a whisper through Twitch Chatter! PogChamp");
  85.     //}
  86.  
  87.     void Cleanup()
  88.     {
  89.         // When you're done, leave the channels and remove the chat listeners.
  90.         TwitchChatClient.singleton.LeaveChannel(chatchan);
  91.         TwitchChatClient.singleton.RemoveChatListener(OnChatMessage);
  92.  
  93.         // Also remove any whisper listeners you've added.
  94.        // TwitchChatClient.singleton.RemoveWhisperListener(OnWhisper);
  95.     }
  96.  
  97.     // You'd define your chat message callback like this:
  98.     public void OnChatMessage(ref TwitchChatMessage msg)
  99.     {
  100.         // Do something with the message here.
  101.         if (msg.channelName == datachan)
  102.         {
  103.             string[] ii = msg.chatMessagePlainText.Split(' ');
  104.             switch (ii[0])
  105.             {
  106.                 case "m":
  107.                     //move
  108.  
  109.                     break;
  110.  
  111.             }
  112.             if (msg.userName == chatchan)
  113.             {
  114.                 //this is a athoritive msg
  115.  
  116.             }
  117.             else
  118.             {
  119.  
  120.  
  121.             }
  122.  
  123.         }
  124.         else if (msg.channelName == worldchan)
  125.         {
  126.  
  127.         }
  128.         else if (msg.channelName == chatchan)
  129.         {
  130.  
  131.         }
  132.     }
  133.  
  134.     // You'd define your whisper callback like this:
  135.     public void OnWhisper(ref TwitchChatMessage msg)
  136.     {
  137.         // Do something with the whisper here.
  138.     }
  139.  
  140.  
  141. }
  142. ====================================================================================================
  143. ====================================================================================================
  144.  
  145.  
  146. using System.Collections;
  147. using System.Collections.Generic;
  148. using UnityEngine;
  149. using UnityEngine.EventSystems;
  150.  
  151. public class submitcommand : MonoBehaviour
  152. {
  153.  
  154.     UnityEngine.UI.InputField infi;
  155.     void Start()
  156.     {
  157.         infi = GetComponent<UnityEngine.UI.InputField>();
  158.  
  159.     }
  160.  
  161.     public void cmd(string i)
  162.     {
  163.         if (i != "")
  164.         {
  165.             //  print(i);
  166.             infi.text = "";
  167.             infi.Select();
  168.             infi.ActivateInputField();
  169.  
  170.             string[] ii = i.ToLower().Split(' ');
  171.  
  172.             switch (ii[0])
  173.             {
  174.                 case "say":
  175.                     print(i);
  176.                    TwitchChatClient.singleton.SendMess(TwitchChatClient.singleton.net.chatchan, i.Remove(0, 4));
  177.                     break;
  178.             }
  179.  
  180.  
  181.  
  182.  
  183.         }
  184.  
  185.     }
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement