public static int HandleGUIResync(int SourceServerId, string ResyncCommand, ACR_ServerCommunicator Script)
{
try
{
ResyncState RemoteResyncInfo;
//
// Deserialize the remote resynchronization state. On null, an
// obviously invalid request was received. Otherwise a protocol
// violation that is atypical was received and an exception is
// raised.
//
if ((RemoteResyncInfo = ResyncState.FromString(ResyncCommand)) == null)
{
Script.WriteTimestampedLogEntry(String.Format(
"ACR_ServerCommunicator.GUIResynchronizer.HandleGUIResync({0}, {1}): Invalid request.",
SourceServerId,
ResyncCommand));
return ACR_ServerCommunicator.FALSE;
}
//
// If a request was not already enqueued for this player, then
// enqueue it.
//
var ResyncInfo = (from RS in PlayerResyncStates
where RS.PlayerId == RemoteResyncInfo.PlayerId
select RS).FirstOrDefault();
if (ResyncInfo == null)
{
//
// If the player is logged on, directly enqueue the execute
// request now. Otherwise, wait for the ClientEnter event
// as the player might still reside on the remote server.
//
foreach (uint PCObject in Script.GetPlayers(true))
{
PlayerState State;
if ((State = Script.TryGetPlayerState(PCObject)) == null)
continue;
if (State.PlayerId != RemoteResyncInfo.PlayerId)
continue;
ResynchronizePlayerState(RemoteResyncInfo, PCObject, Script);
return ACR_ServerCommunicator.TRUE;
}
//
// Enqueue the request so that it can be processed at
// ClientEnter time.
//
PlayerResyncStates.Add(RemoteResyncInfo);
}
else
{
//
// Update the resync flags to match the new request.
//
ResyncInfo.ResyncFlags = RemoteResyncInfo.ResyncFlags;
}
}
catch (Exception e)
{
Script.WriteTimestampedLogEntry(String.Format(
"ACR_ServerCommunicator.GUIResynchronizer.HandleGUIResync({0}, {1}): Exception: {0}",
SourceServerId,
ResyncCommand,
e));
return ACR_ServerCommunicator.FALSE;
}
return ACR_ServerCommunicator.TRUE;
}