You should use locks to make sure that your code won't be doing ugly things when an action is called simultaneously and the action before hasn't finished.
For example in Utils.Out.cs it should be like:
using System;
namespace NettyBase
{
class Out
{
private static object WriteLock = new object();
/// <summary>
/// That should replace the Console.WriteLine with a little more ordered version.
/// </summary>
/// <param name="message">That's where the input text goes</param>
/// <param name="header">This parameter is optional and it stands for the [header] before the text</param>
/// <param name="color">This parameter is optional and it is chosing the color you would like the text to be</param>
public static void WriteLine(string message, string header = "", ConsoleColor color = ConsoleColor.Gray)
{
lock(WriteLock)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("[" + DateTime.Now + "]");
if (header != "")
{
Console.Write("[");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(header);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("]");
}
Console.Write(" - ");
Console.ForegroundColor = color;
Console.WriteLine(message);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
}
You should use locks to make sure that your code won't be doing ugly things when an action is called simultaneously and the action before hasn't finished.
For example in Utils.Out.cs it should be like:
using System;
namespace NettyBase
{
class Out
{
private static object WriteLock = new object();
/// <summary>
/// That should replace the Console.WriteLine with a little more ordered version.
/// </summary>
/// <param name="message">That's where the input text goes</param>
/// <param name="header">This parameter is optional and it stands for the [header] before the text</param>
/// <param name="color">This parameter is optional and it is chosing the color you would like the text to be</param>
public static void WriteLine(string message, string header = "", ConsoleColor color = ConsoleColor.Gray)
{
lock(WriteLock)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("[" + DateTime.Now + "]");
if (header != "")
{
Console.Write("[");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(header);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("]");
}
Console.Write(" - ");
Console.ForegroundColor = color;
Console.WriteLine(message);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
}
As far as I know, locks are only necessary when using lists/dictionaries/arrays which could be changed while they are being used. I might be wrong though.
As far as I know, locks are only necessary when using lists/dictionaries/arrays which could be changed while they are being used. I might be wrong though.
Locks can be used when you know that an action could take some time (to write some lines) and it can be called concurrently.
While the action is performing some text color changes and writing, the action is again called.
With a lock, you make sure that the lines will be full written (thread-safe).
Locks can be used when you know that an action could take some time (to write some lines) and it can be called concurrently.
While the action is performing some text color changes and writing, the action is again called.
With a lock, you make sure that the lines will be full written (thread-safe).
You can't change the colour in the same string. (or atleast I think so)
Code:
using System;
namespace NettyBase
{
class Out
{
/// <summary>
/// That should replace the Console.WriteLine with a little more ordered version.
/// </summary>
/// <param name="message">That's where the input text goes</param>
/// <param name="header">This parameter is optional and it stands for the [header] before the text</param>
/// <param name="color">This parameter is optional and it is chosing the color you would like the text to be</param>
public static void WriteLine(string message, string header = "", ConsoleColor color = ConsoleColor.Gray)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("[" + DateTime.Now + "]");
Console.ForegroundColor = ConsoleColor.DarkGray;
header = header == "" ? header : "[" + header + "]";
Console.Write(header);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(" - ");
Console.ForegroundColor = color;
Console.WriteLine(message);
//Console.ForegroundColor = ConsoleColor.Gray; // u'll reset the color at the start anyways.
}
}
}
using System;
namespace NettyBase
{
class Out
{
private static object WriteLock = new object();
/// <summary>
/// That should replace the Console.WriteLine with a little more ordered version.
/// </summary>
/// <param name="message">That's where the input text goes</param>
/// <param name="header">This parameter is optional and it stands for the [header] before the text</param>
/// <param name="color">This parameter is optional and it is chosing the color you would like the text to be</param>
public static void WriteLine(string message, string header = "", ConsoleColor color = ConsoleColor.Gray)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("[" + DateTime.Now + "]");
Console.ForegroundColor = ConsoleColor.DarkGray;
header = header == "" ? header : "[" + header + "]";
Console.Write(header);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(" - ");
Console.ForegroundColor = color;
Console.WriteLine(message);
//Console.ForegroundColor = ConsoleColor.Gray; // u'll reset the color at the start anyways.
}
}
}
Oh look. 2 less stream writings.
That code is still not thread safe and locks are indeed needed if your application uses more than one thread (which it will if it's a server, because single threaded servers are slow as fuck).
That code is still not thread safe and locks are indeed needed if your application uses more than one thread (which it will if it's a server, because single threaded servers are slow as ****).
And if you want a fast server which is threadsafe then don't write every ******* bullshit in the console. Try to prevent using the console that much.
@olitis Thank you a lot for the lock I was wondering why when I start the chat server's task it writes on top of itself.
Is anyone able to make packet / socket redirect code on PHP in order to get all the packets from the emulator and handle them there instead of inventory.php.
@olitis Thank you a lot for the lock I was wondering why when I start the chat server's task it writes on top of itself.
Is anyone able to make packet / socket redirect code on PHP in order to get all the packets from the emulator and handle them there instead of inventory.php.
Hello, I'm looking for a card based game botting tutorial. 04/02/2014 - AutoIt - 4 Replies Hello epvpers, I just registered and would like first of all to thank you for the opportunity to learn some coding.
Secondly, I'd like to apologize in advance if I'm breaking any forum rules that I might have not seen.
And thirdly, here is my request: I would like to know if there is any tutorials on how to make a game bot.
The particulars are that its a card based game and from what I read so far a pixel search approach its recommended. I'd like to know if there are other approaches...
server based on taiwan server files (give me your opinion) Fast ^_^ 12/09/2013 - SRO PServer Advertising - 4 Replies I got a TW Server files and i launched it , and fixed all bugs and problems its now 100% working
So what do u think i have to open it (PvP Or PvE) & The Cap ! But remember that there's no any bot works with it except Kbot i think btw give us your opinion !
Thanks :)
[C#] DarkOrbit Encoding/Decoding from Netty 05/18/2013 - DarkOrbit - 5 Replies Hello, today i bring you how to encode and decode the packets of the new darkorbit(which uses netty).
Dictionary:
Short - 2 bytes
Int - 4 bytes
Bool - 1 byte
Str or UTF - Short Length of String + String
The structure of the packets are:
1 - Short Length of all packet
Ecsro Based Server 90SKILL And 90 Cap first realy oldschool server + Beginner Event 08/14/2012 - SRO PServer Advertising - 375 Replies hey guys,
After a long downtime we are now back online would be finde to see You again
Stall Is Disabled In Gameserver so Dupe Unable To Use
Events for beginning :
20.08.2012 Have fun :)
First account Gets 200free silk
Normal Events :