Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple master servers. #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sharifmarat
Copy link

Changed master setting from a single string to a list of strings
Updated Master server's query requests to re-try in case of an error from a master server. Number of re-tries is limited to number of master servers.
Dedicated server sends announcements to all master servers.

Copy link

@lewinjh lewinjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, nice work, especially if this is your first time using Delphi! I've written some comments in the code for you.

FreeAndNil(fMasterServer);
for i := Low(fMasterServers) to High(fMasterServers) do
FreeAndNil(fMasterServers[i]);
fMasterServers := nil;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be SetLength(fMasterServers, 0);

if aMasterServerAddress[i] <> fMasterServers[i].MasterServerAddress then
recreate := true;

StatusMessage('(Re-)creating connections to master servers');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything from here should only run if recreate is true?

StatusMessage('(Re-)creating connections to master servers');
for i := Low(fMasterServers) to High(fMasterServers) do
FreeAndNil(fMasterServers[i]);
fMasterServers := nil;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line: fMasterServers := nil;


procedure TKMMasterServer.Error(const S: string);
begin
if Assigned(fOnError) then fOnError(S);
gLog.AddTime('Error from master server ' + GetActiveServer());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't log it here, use fOnError to report problems and the owner can decide what to do about it

@@ -16,19 +16,29 @@ TKMMasterServer = class
private
fIsDedicated: Boolean;

fMasterServerAddress: TStringList; // List with at least one master server
fActiveMasterServer: Integer; //Currently active master server
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if clients always query every master server and merge the results. Otherwise two friends could see different lists of servers if the main master server is unreliable but still online (e.g. not responding 50% of the time). It's not a big deal to run a few HTTP requests each time, the amount of data is small.

If you do it this way you'll need one fHTTPClient per server, and TKMServerQuery.ReceiveServerList will need to ignore duplicates.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this point, there will be no harm if receive and adjoin replies from many masterservers, since its possbile to ignore duplicates

@@ -11,7 +11,7 @@ TKMDedicatedServer = class
private
fLastPing, fLastAnnounce: cardinal;
fNetServer: TKMNetServer;
fMasterServer: TKMMasterServer;
fMasterServers: array of TKMMasterServer;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since TKMMasterServer can deal with multiple servers, wouldn't it be better to have one here and let TKMMasterServer deal with each server like we do for client side? (i.e. make server/client handle it more similarly)

@reyandme
Copy link
Owner

@lewinjh Thank you for detailed PR review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants