The worst fCraft mod that exists.

For all mod-related questions and custom code.
Post Reply
Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

The worst fCraft mod that exists.

Post by Jonty800 »

This is an Omegle chat command. Use at your own risk, lol.

1. Make a new class

Code: Select all

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Collections;
using fCraft;

public class OmegleBot
{
    private string id;
    Player player;
    public string ID
    {
        get { return id; }
        set { id = value; }
    }

    private string lastMessage = String.Empty;
    public string LastMessage
    {
        get { return lastMessage; }
        set { lastMessage = value; }
    }

    private bool paired = false;
    public bool Paired
    {
        get { return paired; }
        set { paired = value; }
    }

    private Thread t;
    public Thread Thread
    {
        get { return t; }
        set { t = value; }
    }
    public OmegleBot() 
    {

    }
    public OmegleBot(Player player_)
    {
        player = player_;
        // Logic
        Paired = true;
        ID = Connect();
    }

    public string Connect()
    {
        //gets your ID, Request() doesnt seem to work for this
        try
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://omegle.com/start");
            request.Method = "POST";
            WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            ID = reader.ReadToEnd().Replace("\"", "");
            response.Close(); 
            reader.Close(); reader.Dispose();
            t = new Thread(EventWatcherThread);
            t.Start();
            return ID;
        }
        catch
        {
            player.Message(Color.Olive + "(Omegle)" + "&WCouldn't get a new chatter ID");
            return String.Empty;
        }
    }

    public void Disconnect()
    {
        Request("http://www.omegle.com/disconnect", "id=" + ID);
        player.OmBot = null;
        player.Message(Color.Olive + "(Omegle)You have disconnected");
        t.Abort();
    }

    public void Say(string what)
    {
        try
        {
            player.Message(Color.Olive + "(Omegle)You: " + what);
            Request("http://www.omegle.com/send", "id=" + ID + "&msg=" + what);
        }
        catch
        {
            player.Message(Color.Olive + "(Omegle)&WSomething went wrong with sending the /Om message");
        }
    }

    private void EventWatcherThread()
    {
        while (true)
        {
            if (Paired)
                GetEvents();
            else
                Disconnect();

            Thread.Sleep(1000);
        }
    }

    private void GetEvents()
    {
        string event_json = Request("http://www.omegle.com/events", "id=" + ID);

        if (event_json != "null")
        {
            Hashtable events = ParseJSON(event_json);
            HandleEvents(events);
        }
    }
    private void HandleEvents(Hashtable events)
    {
        IDictionaryEnumerator en = events.GetEnumerator();
        while (en.MoveNext())
        {
            switch (en.Key.ToString().Replace("[", "").Replace("]", ""))
            {
                case "typing":
                    //player.Message(Color.Olive + "(Omegle)" + "Stranger is typing");
                    break;

                case "waiting":
                    break;

                case "connected":
                    Paired = true;
                    player.Message(Color.Olive + "(Omegle)Found a new stranger!");
                    break;
                case "null":
                    Disconnect();
                    break;

                    //this was just laziness.
                default:
                        string message = en.Value.ToString().Replace("\"[[gotmessage\", ", "").Replace("]]", "");
                        player.Message(Color.Olive + "(Omegle)Stranger: " + message);
                        break;
                case "strangerDisconnected":
                    Paired = false;
                    player.Message(Color.Olive + "(Omegle)The stranger has disconnected.");
                    break;
            }

        }

    }

    private Hashtable ParseJSON(string json)
    {
        Hashtable result = new System.Collections.Hashtable();

        // [["connected"], ["gotMessage", "lol"]]
        json = json.Remove(0, 1);
        json = json.Remove(json.Length - 1, 1);
        string[] json_messages = json.Split(']');

        foreach (string message in json_messages)
        {
            string m = message;

            if (m == "")
                break;

            if (message.Substring(0, 2) == ", ")
                m = message.Remove(0, 2);

            m.Remove(0, 1); // Remove ["

            string[] split = m.Split(',');
            string key = "", value = "";

            if (split.Length == 1)
            {
                key = split[0];

                // Strip off " surrounding key
                key = key.Remove(0, 2);
                key = key.Remove(key.Length - 1, 1);
            }

            if (split.Length == 2)
            {
                value = split[1].Remove(0, 1);

                // Strip off " surrounding value
                value = value.Remove(0, 1);
                value = value.Remove(value.Length - 1, 1);
            }

            try
            {
                result.Add(key, value);
            }
            catch { }
        }

        return result;
    }

    private string Request(string url, string parameters)
    {
        try
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "POST";
            request.Host = "omegle.com";

            byte[] byteArray = Encoding.UTF8.GetBytes(parameters);

            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();

            reader.Close();
            reader.Dispose();
            dataStream.Close();
            response.Close();
            return responseFromServer;
        }
        catch
        {
            player.Message(Color.Olive + "(Omegle)" + "&WFailed to send the request to Omegle.com :(");
            Disconnect();
            return String.Empty;
        }
    }
}
2. Make an instance of Omegle Chat, per player
in player.cs:

Code: Select all

 public OmegleBot OmBot;
3. Add the command - usually in chat commands

Code: Select all

static readonly CommandDescriptor CdOmegle = new CommandDescriptor
        {
            Name = "Om",
            Category = CommandCategory.Chat,
            IsConsoleSafe = false,
            Permissions = new[] { Permission.Chat },
            Usage = "/Om Message",
            Help = "Yes, help.",
            Handler = OmHandler
        };

        static void OmHandler(Player player, Command cmd)
        {
            if (player.OmBot == null)
            {
                player.OmBot = new OmegleBot(player);
            }
            else
            {
                string Message = cmd.NextAll();
                if (Message == null)
                {
                    player.Message("Your message cannot be zero length");
                    return;
                }
                player.OmBot.Say(Message);
            }
        }
You cannot use certain BBCodes: [img].

User avatar
PhoneBook_
Offline
Posts: 118
Joined: June 28th, 2012, 10:58 pm
Location: Indiana
Contact:

Re: The worst fCraft mod that exists.

Post by PhoneBook_ »

I'm by no means an expert with C#.... What exactly does this do?
<FCB2> carlos32123: permissiin to deny the deny of the permission of departure denied

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: The worst fCraft mod that exists.

Post by boblol0909 »

phonebookguy wrote:I'm by no means an expert with C#.... What exactly does this do?
It allows you to chat on omegle in fcraft. I don't see why this is the worst mod though.

User avatar
PhoneBook_
Offline
Posts: 118
Joined: June 28th, 2012, 10:58 pm
Location: Indiana
Contact:

Re: The worst fCraft mod that exists.

Post by PhoneBook_ »

what is "omegle"?
<FCB2> carlos32123: permissiin to deny the deny of the permission of departure denied

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: The worst fCraft mod that exists.

Post by boblol0909 »

phonebookguy wrote:what is "omegle"?
A website that puts you in a conversation with a random person.

User avatar
Hellenion
Offline
Posts: 220
Joined: October 20th, 2011, 9:20 am
Location: Subnet
Contact:

Re: The worst fCraft mod that exists.

Post by Hellenion »

Dear Celestia why would you make such a thing? This is horrifying!
A = {x ∈ P(U) | x ∉ x}
Mods:
  1. /Su - Allows players to temporarily become a different rank
  2. /Snap - Like /Line but only draws straight or diagonal lines.
  3. pre-0.630 skip/none block

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: The worst fCraft mod that exists.

Post by Jonty800 »

Reminded: The terms of this command are the same as omegle.com:
Do not behave inappropriately on Omegle, and understand that human behavior is fundamentally uncontrollable. The people you encounter on Omegle may not behave appropriately. Use Omegle at your own peril. Do not use Omegle if you are under 13, or without a parent/guardian's permission if you are under 18. Disconnect if anyone makes you feel uncomfortable. OMEGLE IS NOT PROVIDED WITH ANY WARRANTY, EXPRESS OR IMPLIED, AND THE OWNER OF OMEGLE DOES NOT ACCEPT LIABILITY OR RESPONSIBILITY FOR ANY LOSS OR DAMAGE OF ANY KIND ARISING DIRECTLY OR INDIRECTLY FROM THE USE OF OMEGLE, except to the minimum extent that warranty or acceptance of liability are required by law. Please read Omegle's privacy policy.
You cannot use certain BBCodes: [img].

Post Reply