[Release] Hellmouth Broadcast

04/16/2011 17:12 Yaksha#1
Hello,
Well since ive started getting back into C#.net coding and learning the Hellmouth source i decided to give something back. So here it is just a simple broadcast system that brodcasts a new message every 50 seconds(can easily be changed).

Before we start i just want to say thanks to Pro4Never for releasing his source and making me want to brush up on my c# and wanting to learn again :).

Also please give feedback as i want to see improvments that can be made.

OPEN: Extras/Dictionary.cs

FIND:
Code:
public static Dictionary<uint, Client> Waiting = new Dictionary<uint, Client>();
UNDER ADD:
Code:
public static SortedList<int, Broadcast> Broadcasts = new SortedList<int, Broadcast>();
OPEN: Structures/ChatType.cs

FIND:
Code:
Broadcast = 2050,
REPLACE WITH:
Code:
Broadcast = 2500,
OPEN: Program.cs

FIND:
Code:
EffT.Start();
UNDER ADD:
Code:
BroadcastQueue Brd = new BroadcastQueue();
Thread BrdT = new Thread(new ThreadStart(Brd.Run));
BrdT.Start();
OPEN: Tools.cs

FIND:
Code:
public class Effects
ABOVE ADD:
Code:
public class BroadcastQueue
    {
        public void Run()
        {
            while (true)
            {
                if (Dictionary.Clients.Count > 0)
                {
                    if (Dictionary.Broadcasts.Count > 0)
                    {
                       int id = Dictionary.Broadcasts.Keys[0];
                       Packets.ToServer(Packets.Chat(Dictionary.Broadcasts[id].Message, Dictionary.Broadcasts[id].Name, "ALL", Struct.ChatType.Broadcast));
                       Dictionary.Broadcasts.Remove(id);
                       Thread.Sleep(50000);
                    }
                }
            }
        }
    }
CREATE FILE: Objects/Broadcast.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hellmouth
{
    public class Broadcast
    {
        public string Name;
        public string Message;
        public byte Place;
    }
}
OPEN: Packet/PacketHandler.cs

FIND:
Code:
case 2050:
FIND IN:
Code:
case 3:
REPLACE CASE WITH:
Code:
case 3:
{
    if (Client.CP >= 5)
    {
        if (Dictionary.Broadcasts.Count <= 100)
        {
            Client.CP -= 5;
            Broadcast B = new Broadcast();

            B.Name = Client.Name;
            B.Message = Message;
            B.Place = (byte)Dictionary.Broadcasts.Count;

            Dictionary.Broadcasts.Add((Dictionary.Broadcasts.Count), B);
        }
    }                                   
}
break;
END
04/16/2011 19:50 leandrovermelauro#2
thanks bro ;)
04/16/2011 19:53 Secured#3
You made me lol at C#.net

.NET is a framework and not a language. C# is a programming language and VS C# is just a C# compiler.
04/16/2011 20:32 thesamuraivega#4
i have 2 problems you can release a video?
04/16/2011 22:34 hackerboy10#5
i can't find
Quote:
case 2050:
in Packet/PacketHandler.cs
04/16/2011 22:41 thesamuraivega#6
Quote:
Originally Posted by hackerboy10 View Post
i can't find
in Packet/PacketHandler.cs
i have the same problem:confused:
04/17/2011 01:37 pro4never#7
Solution is simple... try making a broadcast and you'll notice an error in console most likely saying unknown packet type XXX (I'm guessing 2050is not in at all) in which case you can just code a new handler for that packet type.


Not a bad release. I'm kinda shocked seeing as almost all of the broadcast systems that got released for the old sources were soooo bad. This is actually decently thought through and should work quite well.

Suggestions for improvement would be minor but why not generate the actual packet to store instead of using a new Broadcast class/struct?

IE:

List<byte[]> Broadcasts = new List<byte[]>();

When creating a new one just generate the chat packet to be sent and add it to broadcast list. The thread then simply checks if Broadcasts has more than 0 elements, if so pulls the first one and simply does a ToServer(Dictionary.Broadcasts[0]); type thing.


Good work though,
P4N
04/17/2011 02:34 Yaksha#8
Sorry i didn't realize packet 2050 was not in the handler its is simple enough to add anyway.

And thank you pro4never ill try and update it when i update it i am still learning your source and how you organize things. but i shall look into it thank you.


EDIT:
also i was thinking of doing a check to see if a timer would better than a thread sleep im not sure which is more efficient processor wise.
04/17/2011 03:03 pro4never#9
I try to avoid timers whenever possible.... but at the same time using an entire thread for something like this does seem a tad excessive.

Personally I'd just do something like...

DateTime LastBroadcast = DateTime.Now; on startup then add in to say... effects thread

if(Broadcasts.Count > 0 && DateTime.Now > LastBroadCast.AddSeconds(30))
{
LastBroadcast = DateTime.Now;
ToServer(Broadcasts[0]);
Broadcasts.RemoveAt(0);
}
04/17/2011 03:06 Yaksha#10
sorry thats what i meant, ok i will try that when i have some spare time thanks
04/17/2011 22:29 onlyme23#11
good job , i don't want to be a bad person but i think you took it from Conquer Emulator source , released by Jacob , there i saw the same system , whatever , you're good because you knew to put it in this source :P
04/18/2011 06:58 hyperco#12
If its true, or not, that he got it from Co Emulator, still being a great job :P
05/03/2011 06:19 denominator#13
Code:
Error	1	The type or namespace name 'Broadcast' could not be found (are you missing a using directive or an assembly reference?)	C:\Users\Alan\Downloads\HellmouthDB\Extra\Dictionary.cs	20	39	Hellmouth
Code:
Error	2	The type or namespace name 'Broadcast' could not be found (are you missing a using directive or an assembly reference?)	C:\Users\Alan\Downloads\HellmouthDB\Extra\Dictionary.cs	20	83	Hellmouth