- Code: Select all
public override void UserJoined(Player player)
{
//get and set parameters
foreach (KeyValuePair<string, string> info in player.JoinData)
{
if (info.Key == "user_name")
{ boss_names[PlayerCount - 1] = info.Value; }
if (info.Key == "hx")
{ boss_playerInfo[PlayerCount - 1, 0] = Convert.ToInt32(info.Value); }
if (info.Key == "hy")
{ boss_playerInfo[PlayerCount - 1, 1] = Convert.ToInt32(info.Value); }
if (info.Key == "health")
{ boss_playerInfo[PlayerCount - 1, 2] = Convert.ToInt32(info.Value); }
if (info.Key == "damage")
{ boss_playerInfo[PlayerCount - 1, 3] = Convert.ToInt32(info.Value); }
}
//start timer if need
if (PlayerCount == 1)
{
this.boss_timer = AddTimer(delegate
{
bla-bla-bla...
}, 300000);
}
}
The problem is if 2 players connect to the room simultaneously "if (PlayerCount == 1)" doesnt work because for example first player connects in 0.0 sec and his information saves in an array. In this time the second player enter in this room for example in 0.01sec. So when the 1st player arive to the "if (PlayerCount == 1)" point PlayerCount is already 2, not 1. So the timer doesnt start. I had such problem in the past, and I created a timer on the client side to resolve this problem. But now it will not work. So how I can fix this issue on the server side?