Hi all.
A few month ago, i started creating my own private server for a certain game. I've never been good with encryption/decryption, so first i never could start creating one... but then somebody wrote a dll-file with the functions in it, so i began.
Anyway, i've written the code for letting monsters or 'mobs' walk around. This is the class for the monster:
CODE
public class Mob
{
public String id, x, cy, fh;
public String mid;
public Boolean spawned;
public Timer mobTimer = new Timer(1000);
private int timerSeconds;
public Mob()
{
spawned = false;
timerSeconds = 0;
}
public void StartMob()
{
mobTimer.Elapsed += new ElapsedEventHandler(mobTimer_Elapsed);
mobTimer.Enabled = true;
}
private void mobTimer_Elapsed(object source, ElapsedEventArgs e)
{
timerSeconds++;
String data = "";
//Global.timerMonster++;
data = "9A 00";
data += Work.DecimalToHex(int.Parse(mid), 4);
//data = "9A 00 6F 0C 00 00";
data += Work.DecimalToHex(timerSeconds, 2);
data += "00 00 00 00 00";
Global.allChars[0] = Packets.SendPacket(Global.allChars[0], data);
}
}
So, lets say, in a map i spawn some 20 monsters, everyone is an object of the class Mob, and for each object i call the StartMob() function, so each mob gets a timer (every second sends a packet to the client)
Now here's the problem, when i've many monsters like 20, my server crashes after some 2 - 4 seconds, and visual studio 2008 tells me the following:
Unhandled Exception: System.AccessViolationException: Attempted to read or
write protected memory. This is often an indication that other memory is corrupt.
The less monsters walk around, the less chance my server crashes...
I really don't know what causes this error
Before i added the monster movement i had it just one time i think (when i was jumping together with someone else around). Also, when it crashes, visual studio points with the error message to this function (in another class):
content = Decrypt(this.maplechar.getSendIV(), content.Substring(8, content.Length - 8));
The Decrypt function is from the dll i use... it decrypts an incoming packet from the client (content).
Well... this error is really bugging me :S i hope somebody here knows something of this error.