-
Notifications
You must be signed in to change notification settings - Fork 3
/
mlkhs.pas
142 lines (120 loc) · 4.05 KB
/
mlkhs.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
{
MyLittleKaraoke high score plugin
Copyright (C) 2015 Andrew Cook
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
}
library mlkhs;
{$MODE Delphi}
uses UWebSDK
,sysutils
,classes
,fphttpclient
,fpjson
;
procedure WebsiteInfo (var Info: TWebsiteInfo); {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
begin
Info.ID := 0; // seems to be ignored
Info.Name := 'My Little Karaoke';
end;
exports WebsiteInfo;
function SendInfoToJson (SendInfo: TSendInfo): string;
begin
with TJSONObject.Create() do begin
Add('username', SendInfo.Username);
Add('password', SendInfo.Password);
Add('score', Inttostr(SendInfo.ScoreInt));
Add('scoreline', Inttostr(SendInfo.ScoreLineInt));
Add('scoregolden', Inttostr(SendInfo.ScoreGoldenInt));
Add('song', SendInfo.MD5Song);
Add('level', Inttostr(SendInfo.Level));
Result := AsJSON;
Free;
end;
end;
function SendScore (SendInfo: TSendInfo): integer; {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
var
url: UTF8String;
begin
{
Returns:
0: ScreenPopupError.ShowPopup(Language.Translate('WEBSITE_NO_CONNECTION'));
2: ScreenPopupError.ShowPopup(Language.Translate('WEBSITE_LOGIN_ERROR'));
3: ScreenPopupInfo.ShowPopup(Language.Translate('WEBSITE_OK_SEND'));
4: ScreenPopupError.ShowPopup(Language.Translate('WEBSITE_ERROR_SCORE'));
5: ScreenPopupError.ShowPopup(Language.Translate('WEBSITE_ERROR_SCORE_DUPLICATED'));
7: ScreenPopupError.ShowPopup(Language.Translate('WEBSITE_ERROR_SONG'));
}
Result := 4; // WEBSITE_ERROR_SCORE
url := 'https://www.mylittlekaraoke.com/highscores/score/submit';
With TFPHttpClient.Create(Nil) do try
RequestBody := TStringStream.Create(SendInfoToJson(SendInfo));
AddHeader('Content-Type','application/json');
Result := StrToInt(Post(url));
if ResponseStatusCode <> 200 then
Result := 4;
Free;
except
RequestBody.Free;
Free;
end;
end;
exports SendScore;
function EncryptScore (SendInfo: TSendInfo): widestring; {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
begin
Result := SendInfoToJson(SendInfo);
end;
exports EncryptScore;
function Login (LoginInfo: TLoginInfo): byte; {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
begin
{
*****************************
** 100: NOT A VALID DLL :p
** 0: ERROR_CONNECT
** 1: OK_LOGIN
** 2: ERROR_LOGIN
*****************************
}
Result := 1;
end;
exports Login;
function EncryptPassword (LoginInfo: TLoginInfo): widestring; {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
begin
Result := widestring(LoginInfo.Password);
end;
exports EncryptPassword;
function DownloadScore (ListMD5Song: widestring; Level: byte): widestring; {$IFDEF MSWINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
var
url: string;
begin
{
* 0768006477Elena_PM
* Jan 07 22:57:22 <Phase4> so 07680 06477 Elena_PM
* Jan 07 22:57:48 <Phase4> top, average, user
}
url := 'https://www.mylittlekaraoke.com/highscores/score/retrieve';
With TFPHttpClient.Create(Nil) do try
AppendStr(url, '?level=');
AppendStr(url, Inttostr(Level));
AddHeader('Content-Type','text/plain');
RequestBody := TStringStream.Create(ListMD5Song);
Result := widestring(Post(url));
if ResponseStatusCode <> 200 then
Result := widestring('0');
Free;
except
Result := widestring('0');
Free;
end;
end;
exports DownloadScore;
end.