forked from KeyAuth/KeyAuth-CSHARP-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyAuth.cs
More file actions
1549 lines (1319 loc) · 53.5 KB
/
KeyAuth.cs
File metadata and controls
1549 lines (1319 loc) · 53.5 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Security.Cryptography;
using System.Collections.Specialized;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Diagnostics;
using System.Security.Principal;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Threading;
using Cryptographic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Net.Http;
using System.Linq;
using System.Windows;
namespace KeyAuth
{
public class api
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetCurrentProcess();
// Import the required Atom Table functions from kernel32.dll
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern ushort GlobalAddAtom(string lpString);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern ushort GlobalFindAtom(string lpString);
public string name, ownerid, version, path, seed;
/// <summary>
/// Set up your application credentials in order to use keyauth
/// </summary>
/// <param name="name">Application Name</param>
/// <param name="ownerid">Your OwnerID, found in your account settings.</param>
/// <param name="version">Application Version, if version doesnt match it will open the download link you set up in your application settings and close the app, if empty the app will close</param>
public api(string name, string ownerid, string version, string path = null)
{
if (ownerid.Length != 10)
{
Process.Start("https://youtube.com/watch?v=RfDTdiBq4_o");
Process.Start("https://keyauth.cc/app/");
Thread.Sleep(2000);
error("Application not setup correctly. Please watch the YouTube video for setup.");
TerminateProcess(GetCurrentProcess(), 1);
}
this.name = name;
this.ownerid = ownerid;
this.version = version;
this.path = path;
}
#region structures
[DataContract]
private class response_structure
{
[DataMember]
public bool success { get; set; }
[DataMember]
public bool newSession { get; set; }
[DataMember]
public string sessionid { get; set; }
[DataMember]
public string contents { get; set; }
[DataMember]
public string response { get; set; }
[DataMember]
public string message { get; set; }
[DataMember]
public string ownerid { get; set; }
[DataMember]
public string download { get; set; }
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public user_data_structure info { get; set; }
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public app_data_structure appinfo { get; set; }
[DataMember]
public List<msg> messages { get; set; }
[DataMember]
public List<users> users { get; set; }
[DataMember(Name = "2fa", IsRequired = false, EmitDefaultValue = false)] // Ensure mapping to "2fa"
public TwoFactorData twoFactor { get; set; } // Add a property for the 2FA data
}
public class msg
{
public string message { get; set; }
public string author { get; set; }
public string timestamp { get; set; }
}
public class users
{
public string credential { get; set; }
}
[DataContract]
private class user_data_structure
{
[DataMember]
public string username { get; set; }
[DataMember]
public string ip { get; set; }
[DataMember]
public string hwid { get; set; }
[DataMember]
public string createdate { get; set; }
[DataMember]
public string lastlogin { get; set; }
[DataMember]
public List<Data> subscriptions { get; set; } // array of subscriptions (basically multiple user ranks for user with individual expiry dates
}
[DataContract]
private class app_data_structure
{
[DataMember]
public string numUsers { get; set; }
[DataMember]
public string numOnlineUsers { get; set; }
[DataMember]
public string numKeys { get; set; }
[DataMember]
public string version { get; set; }
[DataMember]
public string customerPanelLink { get; set; }
[DataMember]
public string downloadLink { get; set; }
}
#endregion
private static string sessionid, enckey;
bool initialized;
/// <summary>
/// Initializes the connection with keyauth in order to use any of the functions
/// </summary>
public async Task init()
{
Random random = new Random();
// Generate a random length for the string (let's assume between 5 and 50 characters)
int length = random.Next(5, 51); // Min length: 5, Max length: 50
StringBuilder sb = new StringBuilder(length);
// Define the range of printable ASCII characters (32-126)
for (int i = 0; i < length; i++)
{
// Generate a random printable ASCII character
char randomChar = (char)random.Next(32, 127); // ASCII 32 to 126
sb.Append(randomChar);
}
seed = sb.ToString();
checkAtom();
var values_to_upload = new NameValueCollection
{
["type"] = "init",
["ver"] = version,
["hash"] = checksum(Process.GetCurrentProcess().MainModule.FileName),
["name"] = name,
["ownerid"] = ownerid
};
if (!string.IsNullOrEmpty(path))
{
values_to_upload.Add("token", File.ReadAllText(path));
values_to_upload.Add("thash", TokenHash(path));
}
var response = await req(values_to_upload);
if (response == "KeyAuth_Invalid")
{
error("Application not found");
TerminateProcess(GetCurrentProcess(), 1);
}
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
if (json.success)
{
sessionid = json.sessionid;
initialized = true;
}
else if (json.message == "invalidver")
{
app_data.downloadLink = json.download;
}
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
#pragma warning disable IDE0052
private System.Threading.Timer atomTimer;
#pragma warning restore IDE0052
void checkAtom()
{
atomTimer = new System.Threading.Timer(_ =>
{
ushort foundAtom = GlobalFindAtom(seed);
if (foundAtom == 0)
{
TerminateProcess(GetCurrentProcess(), 1);
}
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
}
public static string TokenHash(string tokenPath)
{
using (var sha256 = SHA256.Create())
{
using (var s = File.OpenRead(tokenPath))
{
byte[] bytes = sha256.ComputeHash(s);
return BitConverter.ToString(bytes).Replace("-", string.Empty);
}
}
}
/// <summary>
/// Checks if Keyauth is been Initalized
/// </summary>
public void CheckInit()
{
if (!initialized)
{
error("You must run the function KeyAuthApp.init(); first");
TerminateProcess(GetCurrentProcess(), 1);
}
}
public string expirydaysleft()
{
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Local);
dtDateTime = dtDateTime.AddSeconds(long.Parse(user_data.subscriptions[0].expiry)).ToLocalTime();
TimeSpan difference = dtDateTime - DateTime.Now;
return Convert.ToString(difference.Days + " Days " + difference.Hours + " Hours Left");
}
public static DateTime UnixTimeToDateTime(long unixtime)
{
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Local);
try
{
dtDateTime = dtDateTime.AddSeconds(unixtime).ToLocalTime();
}
catch
{
dtDateTime = DateTime.MaxValue;
}
return dtDateTime;
}
/// <summary>
/// Registers the user using a license and gives the user a subscription that matches their license level
/// </summary>
/// <param name="username">Username</param>
/// <param name="pass">Password</param>
/// <param name="key">License key</param>
public async Task register(string username, string pass, string key, string email = "")
{
CheckInit();
string hwid = WindowsIdentity.GetCurrent().User.Value;
var values_to_upload = new NameValueCollection
{
["type"] = "register",
["username"] = username,
["pass"] = pass,
["key"] = key,
["email"] = email,
["hwid"] = hwid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if (json.success)
load_user_data(json.info);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Allow users to enter their account information and recieve an email to reset their password.
/// </summary>
/// <param name="username">Username</param>
/// <param name="email">Email address</param>
public async Task forgot(string username, string email)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "forgot",
["username"] = username,
["email"] = email,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
}
/// <summary>
/// Authenticates the user using their username and password
/// </summary>
/// <param name="username">Username</param>
/// <param name="pass">Password</param>
public async Task login(string username, string pass, string code = null)
{
CheckInit();
string hwid = WindowsIdentity.GetCurrent().User.Value;
var values_to_upload = new NameValueCollection
{
["type"] = "login",
["username"] = username,
["pass"] = pass,
["hwid"] = hwid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid,
["code"] = code ?? null
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if (json.success)
load_user_data(json.info);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
public async Task logout()
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "logout",
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
public async Task web_login()
{
CheckInit();
string hwid = WindowsIdentity.GetCurrent().User.Value;
string datastore, datastore2, outputten;
start:
HttpListener listener = new HttpListener();
outputten = "handshake";
outputten = "http://localhost:1337/" + outputten + "/";
listener.Prefixes.Add(outputten);
listener.Start();
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
HttpListenerResponse responsepp = context.Response;
responsepp.AddHeader("Access-Control-Allow-Methods", "GET, POST");
responsepp.AddHeader("Access-Control-Allow-Origin", "*");
responsepp.AddHeader("Via", "hugzho's big brain");
responsepp.AddHeader("Location", "your kernel ;)");
responsepp.AddHeader("Retry-After", "never lmao");
responsepp.Headers.Add("Server", "\r\n\r\n");
if (request.HttpMethod == "OPTIONS")
{
responsepp.StatusCode = (int)HttpStatusCode.OK;
Thread.Sleep(1); // without this, the response doesn't return to the website, and the web buttons can't be shown
listener.Stop();
goto start;
}
listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
listener.UnsafeConnectionNtlmAuthentication = true;
listener.IgnoreWriteExceptions = true;
string data = request.RawUrl;
datastore2 = data.Replace("/handshake?user=", "");
datastore2 = datastore2.Replace("&token=", " ");
datastore = datastore2;
string user = datastore.Split()[0];
string token = datastore.Split(' ')[1];
var values_to_upload = new NameValueCollection
{
["type"] = "login",
["username"] = user,
["token"] = token,
["hwid"] = hwid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
bool success = true;
if (json.ownerid == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if (json.success)
{
load_user_data(json.info);
responsepp.StatusCode = 420;
responsepp.StatusDescription = "SHEESH";
}
else
{
Console.WriteLine(json.message);
responsepp.StatusCode = (int)HttpStatusCode.OK;
responsepp.StatusDescription = json.message;
success = false;
}
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
byte[] buffer = Encoding.UTF8.GetBytes("Complete");
responsepp.ContentLength64 = buffer.Length;
Stream output = responsepp.OutputStream;
output.Write(buffer, 0, buffer.Length);
Thread.Sleep(1); // without this, the response doesn't return to the website, and the web buttons can't be shown
listener.Stop();
if (!success)
TerminateProcess(GetCurrentProcess(), 1);
}
/// <summary>
/// Use Buttons from KeyAuth Customer Panel
/// </summary>
/// <param name="button">Button Name</param>
public void button(string button)
{
CheckInit();
HttpListener listener = new HttpListener();
string output;
output = button;
output = "http://localhost:1337/" + output + "/";
listener.Prefixes.Add(output);
listener.Start();
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
HttpListenerResponse responsepp = context.Response;
responsepp.AddHeader("Access-Control-Allow-Methods", "GET, POST");
responsepp.AddHeader("Access-Control-Allow-Origin", "*");
responsepp.AddHeader("Via", "hugzho's big brain");
responsepp.AddHeader("Location", "your kernel ;)");
responsepp.AddHeader("Retry-After", "never lmao");
responsepp.Headers.Add("Server", "\r\n\r\n");
responsepp.StatusCode = 420;
responsepp.StatusDescription = "SHEESH";
listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
listener.UnsafeConnectionNtlmAuthentication = true;
listener.IgnoreWriteExceptions = true;
listener.Stop();
}
/// <summary>
/// Gives the user a subscription that has the same level as the key
/// </summary>
/// <param name="username">Username of the user thats going to get upgraded</param>
/// <param name="key">License with the same level as the subscription you want to give the user</param>
public async Task upgrade(string username, string key)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "upgrade",
["username"] = username,
["key"] = key,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
json.success = false;
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Authenticate without using usernames and passwords
/// </summary>
/// <param name="key">Licence used to login with</param>
public async Task license(string key, string code = null)
{
CheckInit();
string hwid = WindowsIdentity.GetCurrent().User.Value;
var values_to_upload = new NameValueCollection
{
["type"] = "license",
["key"] = key,
["hwid"] = hwid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid,
["code"] = code ?? null
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if (json.success)
load_user_data(json.info);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Checks if the current session is validated or not
/// </summary>
public async Task check()
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "check",
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Disable two factor authentication (2fa)
/// </summary>
public async Task disable2fa(string code)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "2fadisable",
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid,
["code"] = code
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
}
/// <summary>
/// Enable two factor authentication (2fa)
/// </summary>
public async Task enable2fa(string code = null)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "2faenable",
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid,
["code"] = code
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if (json.success)
{
if (code == null) // First time enabling 2FA, no code provided
{
// Display the secret code to the user
Clipboard.SetText(json.twoFactor.SecretCode);
System.Windows.MessageBox.Show($"Your 2FA Secret Code has been copied to your clipboard! \n\n: {json.twoFactor.SecretCode}", "2FA Secret");
}
else // Code provided by the user
{
System.Windows.MessageBox.Show("2FA has been successfully enabled!", "2FA Setup");
}
}
else
{
Thread.Sleep(3000);
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Change the data of an existing user variable, *User must be logged in*
/// </summary>
/// <param name="var">User variable name</param>
/// <param name="data">The content of the variable</param>
public async Task setvar(string var, string data)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "setvar",
["var"] = var,
["data"] = data,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Gets the an existing user variable
/// </summary>
/// <param name="var">User Variable Name</param>
/// <returns>The content of the user variable</returns>
public async Task<string> getvar(string var)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "getvar",
["var"] = var,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
if (json.success)
return json.response;
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
return null;
}
/// <summary>
/// Bans the current logged in user
/// </summary>
public async Task ban(string reason = null)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "ban",
["reason"] = reason,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Gets an existing global variable
/// </summary>
/// <param name="varid">Variable ID</param>
/// <returns>The content of the variable</returns>
public async Task<string> var(string varid)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "var",
["varid"] = varid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
if (json.success)
return json.message;
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
return null;
}
/// <summary>
/// Fetch usernames of online users
/// </summary>
/// <returns>ArrayList of usernames</returns>
public async Task<List<users>> fetchOnline()
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "fetchOnline",
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if (json.success)
return json.users;
return null;
}
/// <summary>
/// Fetch app statistic counts
/// </summary>
public async Task fetchStats()
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "fetchStats",
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if (json.success)
load_app_data(json.appinfo);
}
/// <summary>
/// Gets the last 50 sent messages of that channel
/// </summary>
/// <param name="channelname">The channel name</param>
/// <returns>the last 50 sent messages of that channel</returns>
public async Task<List<msg>> chatget(string channelname)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "chatget",
["channel"] = channelname,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if (json.success)
{
return json.messages;
}
return null;
}
/// <summary>
/// Sends a message to the given channel name
/// </summary>
/// <param name="msg">Message</param>
/// <param name="channelname">Channel Name</param>
/// <returns>If the message was sent successfully, it returns true if not false</returns>
public async Task<bool> chatsend(string msg, string channelname)
{
CheckInit();
var values_to_upload = new NameValueCollection
{
["type"] = "chatsend",
["message"] = msg,
["channel"] = channelname,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if (json.success)
return true;
return false;
}
/// <summary>
/// Checks if the current ip address/hwid is blacklisted
/// </summary>
/// <returns>If found blacklisted returns true if not false</returns>
public async Task<bool> checkblack()
{
CheckInit();
string hwid = WindowsIdentity.GetCurrent().User.Value;
var values_to_upload = new NameValueCollection
{
["type"] = "checkblacklist",
["hwid"] = hwid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var response = await req(values_to_upload);
var json = response_decoder.string_to_generic<response_structure>(response);
if (json.ownerid == ownerid)
{
load_response_struct(json);
if (json.success)
return true;
else
return false;
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
return true; // return yes blacklisted if the OwnerID is spoofed
}
/// <summary>
/// Sends a request to a webhook that you've added in the dashboard in a safe way without it being showed for example a http debugger
/// </summary>
/// <param name="webid">Webhook ID</param>
/// <param name="param">Parameters</param>
/// <param name="body">Body of the request, empty by default</param>
/// <param name="conttype">Content type, empty by default</param>
/// <returns>the webhook's response</returns>
public async Task<string> webhook(string webid, string param, string body = "", string conttype = "")
{