Disconnect and reconnect?

Topics: Admin Tool, Developers
Jan 12, 2012 at 3:53 PM

Hi,

In iOS I'm trying to figure out how to use BF3RCon.NET when the user presses the "home botton" and sends the app to the background.

First in the DidEnterBackground event, I use client.Disconnect() ... but the "quit" command is like 5-10 seconds to complete, so I changed the client.SendRequest("quit") to client.SendAsynchronousRequest("quit").

 

In the WillEnterForeground event i use client.Connect().

 

But no events are happening and suddenly it throws an "Object reference not set to an instance of an object" exception in client ReceiveCallback ->

client.LeftoverData.Add(state.Buffer[i]);

 

How is propper way to disconnect and reconnect in BF3Rcon.Net?

 

Thanks

Mojo

Coordinator
Jan 12, 2012 at 5:56 PM

First, I just fixed that NullReferenceException thanks to your post :D. You can get the latest code in the Source Code tab. I'll do a release sometime soon after I check on other bugs (and whenever the server I use comes back up).

For connecting, RconClient.Connect() is used for an asynchronous connect, and RconClient.ConnectSync() is used for a synchronous connect.

For disconnecting, RconClient.Disconnect() should be used.

Jan 12, 2012 at 7:11 PM

Hi Timiz0r,

Great :)

Strange ... after I downloaded the code from the "Source Code" tab, I can't log on at all now - RconClient.LoggedOn event is never called? Is it a bug?

Also - shouldn't there be an Player.PermanentBan(message) method too?

:)

Thanks.

Mojo

 

Coordinator
Jan 13, 2012 at 2:13 AM

Does RconClient.LogOn(string), which is synchronous, return false immediately or delay for 10 seconds?

I did just check in an update that fixes a bug that could rarely cause that kind of problem. It would rarely occur when reusing an RconClient after disconnect.

Also, I don't plan on working on banlist integration until paging is implemented for it.

Jan 13, 2012 at 2:52 PM
Edited Jan 13, 2012 at 8:05 PM

Hi again :)

If I use rcon.LogOn (m.Password, true), I never get logged on, but if I use rcon.LogOn (m.Password, false), I get logged on fine. In rcon.LogOn (m.Password, true), the "if (threaded)" is true, so the method returns false immediately and the LoggedOn event is never triggered. 

I'm not referrring to loading the ban list :) ... you have a Kick() and a Kick(message) ... and you have a PermenantBan(), but no PermenantBan(message) ... so we can't ban with a reason. :) Here's what is missing in the Player.cs...

public void PermanentBan(string message)
{
    if (!Parent.IsLoggedOn) throw new NotLoggedOnException();
    Parent.InternalSendRequest("banList.add", "name", Name, "perm", message);
}

Furthermore you have some problems in the server.cs file - your indexes is off. Here's what I changed:

Ranked: string ranked = GetServerInfo2(13);
PunkBusterEnabled: string p = GetServerInfo2(14);
PasswordEnabled: string p = GetServerInfo2(15);
Uptime: int sec = GetServerInfo2(16).ToInt32();
RoundTime: int sec = GetServerInfo2(17).ToInt32();
(I haven't checked the rest)

My offer stil stand - if you need RCon password to a populated server, I will lent your mine ... as long as you don't kick and ban randomly ... and don't restart the server. :)  My server is very popular and is almost always populated. It's up to you. :)

Mojo

 

Update: When the RconClient is connected and working fine, I click a button that call this method "RconClient.Disconnect()" ... I wait 10 seconds and then click a button that calls "RconClient.Connect()" ... the Connected event is called fine and in this event, I do a "RconClient.LogOn (myPassword, false);" ... but then the LoggedOn event is never called :( ... any idea what is wrong?

 

UPDATE - here's the bug...

Think I found your bug .... in Disconnect() method, you never set IsLoggedOn to false ... in the "void Reset()" method i added this:

base.IsLoggedOn = false;
Now the LoggedOn event is fired again :)
Coordinator
Jan 13, 2012 at 8:30 PM
Edited Jan 13, 2012 at 8:32 PM

I believe I have found the bug (edit: and it seems you did soon after :D. I also took 25 minutes to write this because I'm multitasking D:)

IsLoggedOn wasn't getting set to false on disconnect, so, when LogOn checked to see if IsLoggedOn was true, it would immediately return false and not try to log on. The newest code has this fix. I assume the line that set IsLoggedOn to false was removed in one of the many changes to the library, although I'm not going to go through all of the old code to find it D:

For banning, I decided to not work on anything relating to the banlist until I implement it in the library (when paging is implemented in the RCON protocol). This includes Player methods, since they will use banlist-integrated methods in the future. Also, I never added methods for the message because back when I wrote then back before there was full documentation.

For the Server properties, GetServerInfo2 gets the packet's words in such a way that index 0 is the last word of teamscores (the target score) and index 1 is the online state. This is done because the teamscores block can contain a different amount of words depending on what gamemode is active. If the values for those are wrong, though, I'll take another look at the serverinfo response, just in case it's different from the documentation.

Finally, regarding your server, I think I'll take you up on that offer until the community I'm with gets theirs back up (they're slow D:). Thanks for the server and all of these bug reports :D

Coordinator
Jan 27, 2012 at 11:08 PM

Regarding your comment about specifying a reason for banning, banlist integration has finally been implemented. I haven't updated the methods in Player yet, but you can Players with this code, as an example:

client.Bans.PermanentBan(player, "aimbot");