Lame Global Chat Help

Lame Global Chat Help

Postby HETAL » 27 May 2013, 14:16

I need someone to add the custom methods so it compiles.




using System;

namespace MCDzienny { public class CmdGlobal : Command {

MCdzienny Server.");

make your own method

your own method

message);

arguement

own method

muted");

properties on the console");

} }
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: Lame Global Chat Help

Postby Conor » 27 May 2013, 16:07

What are you trying to do? Your post is a little baffling, do you want to create a custom command for global chat?

MCDzienny does not currently support global chat, however it does have an IRC option which you can configure in the properties.

So you can set up an IRC channel and use it on two servers which would allow players to chat from outside of minecraft to both servers; however you cannot chat whilst on the server as a player and then have it seen on another server.

If you were just trying to create the command skeleton for a command, then you can create one from the console by typing /cmdcreate [command name]. The file and command skeleton will appear in the folder: extra > commands > source
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Lame Global Chat Help

Postby ismellike » 27 May 2013, 16:46

Well I've been trying to make one, here is what I have

Code: Select all
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System;
using System.Text;

namespace MCDzienny
{
    public class CmdClan : Command
    {
        delegate void AddMessage(string msg);
        const int port = 25567;
        const string broadcastAddress = "255.255.255.255";
        UdpClient receivingClient;
        UdpClient sendingClient;
        Thread receivingThread;
        public string name = "";
        public override string name { get { return "clan"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public CmdClan() { }
        public override void Use(Player p, string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                name = p.PublicName;
                string toSend = p.name + ":\n" + message;
                byte[] data = Encoding.ASCII.GetBytes(toSend);
                sendingClient.Send(data, data.Length);
            }
        }
        public override void Init()
        {
            InitializeSender();
            InitializeReceiver();
        }

        private void InitializeSender()
        {
            sendingClient = new UdpClient(broadcastAddress, port);
            sendingClient.EnableBroadcast = true;
        }

        private void InitializeReceiver()
        {
            receivingClient = new UdpClient(port);

            ThreadStart start = new ThreadStart(Receiver);
            receivingThread = new Thread(start);
            receivingThread.IsBackground = true;
            receivingThread.Start();
        }


        public override void Help(Player p)
        {

        }
        private void Receiver()
        {
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, port);
            AddMessage messageDelegate = MessageReceived;

            while (true)
            {
                byte[] data = receivingClient.Receive(ref endPoint);
                string message = Encoding.ASCII.GetString(data);
            }
        }

        private void MessageReceived(string msg)
        {
            Player.GlobalMessage("%d" + name + "%f:" + msg);
        }
    }
}


I've been getting info from this site.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Lame Global Chat Help

Postby HETAL » 27 May 2013, 20:42

So this coding is of no use until mcdzienny can support global chat.
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: Lame Global Chat Help

Postby ismellike » 29 May 2013, 22:07

I've been testing it and I think this code could work, people would just have to have a port open for 25568.
Maybe Conor or Dzienny can give a little more insight about how to bind sockets, to make it easier.

Code: Select all
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System;
using System.Text;

namespace MCDzienny
{
    public class CmdGchat : Command
    {
        delegate void AddMessage(string msg);
        const int port = 25568;
        const string broadcastAddress = "255.255.255.255";
        UdpClient receivingClient;
       UdpClient sendingClient;
        Thread receivingThread;
        public string sender = "";
        public override string name { get { return "gchat"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Use(Player p, string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                sender = p.PublicName;
                string toSend = p.name + ":\n" + message;
                byte[] data = Encoding.ASCII.GetBytes(toSend);
                sendingClient.Send(data, data.Length);
            }
        }
        public override void Init()
        {
            InitializeSender();
            InitializeReceiver();
        }

        private void InitializeSender()
        {
            sendingClient = new UdpClient(port);
            sendingClient.EnableBroadcast = true;
        }

        private void InitializeReceiver()
        {
            receivingClient = new UdpClient(port);

            ThreadStart start = new ThreadStart(Receiver);
            receivingThread = new Thread(start);
            receivingThread.IsBackground = true;
            receivingThread.Start();
        }


        public override void Help(Player p)
        {

        }
        private void Receiver()
        {
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, port);
            while (true)
            {
                byte[] data = receivingClient.Receive(ref endPoint);
                string msg = Encoding.ASCII.GetString(data);
                Player.GlobalMessage(msg);
            }
        }
    }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Lame Global Chat Help

Postby lucasds12 » 29 May 2013, 22:28

I got a error.
Code: Select all
----5/29/2013 2:20:45 PM ----
Type: FileNotFoundException
Source: mscorlib
Message: Could not find file 'C:\Users\Toshiba Pc\Downloads\MCDzienny9.7.3 (1)\MCDzienny\extra\commands\dll\Cmdcmdfakeshutdown.dll'.
Target: WinIOError
Trace:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.Open(String path, FileMode mode)
   at MCDzienny.Scripting.Load(String command)

Please help.
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.

Re: Lame Global Chat Help

Postby ismellike » 29 May 2013, 22:31

I think you might have been trying to load "Cmdfakeshutdown" instead.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Lame Global Chat Help

Postby dzienny » 29 May 2013, 23:22

It seems very interesting. It should work well for local cross server communication. I will try it out.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Lame Global Chat Help

Postby dzienny » 30 May 2013, 13:54

@ismellike
Unfortunately on /cmdload the following error occurs:
Code: Select all
Type: SocketException
Source: System
Message: Only one usage of each socket address (protocol/network address/port) is normally permitted
Target: DoBind
Trace:    at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.Net.Sockets.UdpClient..ctor(Int32 port, AddressFamily family)
   at System.Net.Sockets.UdpClient..ctor(Int32 port)
   at MCDzienny.CmdGchat.InitializeReceiver()
   at MCDzienny.CmdGchat.Init()
   at MCDzienny.Scripting.Load(String command)
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Lame Global Chat Help

Postby HETAL » 30 May 2013, 15:48

i left out some of the code on my first post here, it wont compile until the methods are added though.

Code: Select all
    using System;

    namespace MCDzienny
    {
    public class CmdGlobal : Command
    {
        // Methods
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/global <message> - Sends a global chat message to every MCdzienny Server.");
        }

        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                this.Help(p);
            }
            else if (message.ToLower() == "help")
            {
                this.Help(p);
            }
            else if //(Server.globalPlayerIrc) no method in MCDzienny, make your own method
            {
                if //((Server.globalIrcNick != null) && (Server.globalIrcNick != "")) no method in MCDzienny, make your own method
                {
                    if (message.Split(new char[] { ' ' })[0] == "procCmdFromDev")
                    {
                        if (Server.devs.Contains(p.name.ToLower()))
                        {
                            //IRCGlobalPlayers.Say(p.name + ": " + message); no method in MCDzienny, make your own method
                            Player.SendMessage(p, "Command Sent.");
                        }
                    }
                    else if (!p.muted)
                    {
                        Player.GlobalMessage("<[Global] " + p.color + p.name + Server.DefaultColor + ": &f" + message);
                        //Server.s.Log("[Global] " + p.name + ": " + message, false, false, false, true); needs fifth arguement
                        //IRCGlobalPlayers.Say(p.name + ": " + message); no method in MCDzienny, make your own method
                    }
                    else
                    {
                        Player.SendMessage(p, "Cannot send message to MCdzienny Global Chat while muted");
                    }
                }
                else
                {
                    Player.SendMessage(p, "Cannot send message to MCdzienny Global Chat");
                    Player.SendMessage(p, "The Server Owner needs to configure a Global IRC 'Nick' first in properties on the console");
                }
            }
            else
            {
                Player.SendMessage(p, "MCdzienny Global Chat has been disabled by the server owner");
            }
        }

        // Properties
        public override LevelPermission defaultRank
        {
            get
            {
                return LevelPermission.Guest;
            }
        }

        public override bool museumUsable
        {
            get
            {
                return true;
            }
        }

        public override string name
        {
            get
            {
                return "global";
            }
        }

        public override string shortcut
        {
            get
            {
                return "gl";
            }
        }

        public override string type
        {
            get
            {
                return "other";
            }
        }
    }
    }

YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Next

Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 5 guests

cron