Skip to content

Commit

Permalink
Добавлен мониторинг, исправлена бага в тиках
Browse files Browse the repository at this point in the history
  • Loading branch information
merlokk committed Jun 26, 2012
1 parent 260ebd9 commit 7bf3fce
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
17 changes: 17 additions & 0 deletions uDefs.pas
Expand Up @@ -111,6 +111,9 @@ function VarToIntDef(v: variant; default: integer): integer;
function VarToInt64Def(v: variant; default: int64): int64;
function VarToBoolDef(v: variant; default: boolean): boolean;

// datetime
function SecMinToStr(dt: TDateTime): string;

implementation

var
Expand Down Expand Up @@ -177,6 +180,20 @@ function VarToBoolDef(v: variant; default: boolean): boolean;
if VarToStr(v) = '0' then Result := false;
end;

// datetime
function SecMinToStr(dt: TDateTime): string;
var
n: integer;
begin
n := Trunc(dt / OneSecond);
if n > 100 then
Result := IntToStr(n div 60) + 'm'
else
Result := IntToStr(n) + 's'

end;


{ FriendRec }

procedure TFriendRec.Clear;
Expand Down
5 changes: 4 additions & 1 deletion uGameItems.pas
Expand Up @@ -283,7 +283,8 @@ TMWorld = class
function GetSWFRevisionAppID: string;
function GetOwnerID: int64;
public
LastUpdate: TDateTime;
LastUpdate,
LastRoomChange: TDateTime;
LastHeader: TWorldHeader;

Friends: TFriendRecArray;
Expand Down Expand Up @@ -683,6 +684,8 @@ procedure TMWorld.Clear;
FValid := false;
FUserDisabled := false;
LastHeader.Clear;
LastUpdate := 0;
LastRoomChange := 0;
SetLength(Friends, 0);
SetLength(Barn, 0);
SetLength(RecvdGift, 0);
Expand Down
1 change: 1 addition & 0 deletions uMPServ.pas
Expand Up @@ -518,6 +518,7 @@ function TMPServer.GetUserStat(World: TMWorld; RoomID: integer; StartNewSession:
FSessionKey := World.LastHeader.SessionKey;

World.CheckRoomInformation(World.LastHeader.RoomInformation);
World.LastRoomChange := Now;

Result := true;
AddLog('server_time=' + IntToStr(World.LastHeader.ServerTime) +
Expand Down
14 changes: 14 additions & 0 deletions uMain.dfm
Expand Up @@ -379,6 +379,20 @@ object MainFrm: TMainFrm
Height = 16
Caption = '---'
end
object Label18: TLabel
Left = 290
Top = 38
Width = 100
Height = 16
Caption = 'Last upd/room ch'
end
object lbLastUpd: TLabel
Left = 396
Top = 38
Width = 15
Height = 16
Caption = '---'
end
object lbLog: TListBox
Left = 3
Top = 67
Expand Down
15 changes: 13 additions & 2 deletions uMain.pas
Expand Up @@ -4,7 +4,7 @@ interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, DateUtils,
uFasade, uLogger, uDB, uGameItems, uMPServ, uDefs;

type
Expand Down Expand Up @@ -59,6 +59,8 @@ TMainFrm = class(TForm)
lbTourists: TLabel;
Label17: TLabel;
lbNextWorkInt: TLabel;
Label18: TLabel;
lbLastUpd: TLabel;
procedure btInitClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btLoadDatrabaseClick(Sender: TObject);
Expand Down Expand Up @@ -263,6 +265,7 @@ procedure TMainFrm.SetParamGroup(grp: string);
procedure TMainFrm.Timer1Timer(Sender: TObject);
var
world: TMWorld;
dt: TDateTime;
begin
Timer1.Enabled := false;
try
Expand All @@ -284,7 +287,14 @@ procedure TMainFrm.Timer1Timer(Sender: TObject);
lbTourists.Caption := world.GetRoomResource(2, 'tourists') + '/' +
world.GetRoomResource(2, 'tourist_capacity');
lbCurRoom.Caption := IntToStr(TMPServer.GetInstance.CurrRoomID);
lbNextWorkInt.Caption := DateTimeToStr(Fasade.NextWorldUpdate);
dt := Fasade.NextWorldUpdate;
if dt > now - 1 then
lbNextWorkInt.Caption := SecMinToStr(Fasade.NextWorldUpdate - Now)
else
lbNextWorkInt.Caption := 'never';

lbLastUpd.Caption := SecMinToStr(Now - world.LastUpdate) + '/' +
SecMinToStr(Now - world.LastRoomChange);

Fasade.PaintGraf(world, imGraph.Canvas);
end
Expand All @@ -296,6 +306,7 @@ procedure TMainFrm.Timer1Timer(Sender: TObject);
lbTourists.Caption := '---';
lbCurRoom.Caption := '---';
lbNextWorkInt.Caption := '---';
lbLastUpd.Caption := '---';
end;
end;

Expand Down
7 changes: 6 additions & 1 deletion uTasks.pas
Expand Up @@ -712,6 +712,7 @@ procedure TMTaskWorldUpdate.IntExecute;
world := TMWorld.GetInstance;
FMPServ.GetRevision(world);

sleep(500);
// first request to MP server
FMPServ.GetUserStat(world, 0, true);
room0 := world.GetRoom(0);
Expand All @@ -721,6 +722,7 @@ procedure TMTaskWorldUpdate.IntExecute;
room := world.GetRoom(i);
if (room = nil) or (not room.Avaliable) then continue;

sleep(2000);
FMPServ.GetUserStat(world, i);
end;

Expand Down Expand Up @@ -878,7 +880,7 @@ procedure TMTaskCurRoomWork.IntExecute;
// we have "old" ticks - older then 60 seconds or
// we have no more ticks in 22 seconds
if (room.FieldsExecuteCount(true, false, 0, Now - 5 * OneSecond) > 30) or
(room.FieldsExecuteCount(true, false, Now - 60 * OneSecond, Now - 5 * OneSecond) > 0) or
(room.FieldsExecuteCount(true, false, 0, Now - 60 * OneSecond) > 0) or
(room.FieldsExecuteCount(true, false, Now - 5 * OneSecond, Now + 22 * OneSecond) <= 0)
then
begin
Expand Down Expand Up @@ -948,6 +950,9 @@ procedure TMTaskCurRoomWork.IntExecute;
' nWork:' + IntToStr(nWork)
);
FMPServ.GetUserStat(world, i);

// if we changed room - end of the task!!!
exit;
end;
except
exit;
Expand Down

0 comments on commit 7bf3fce

Please sign in to comment.