forked from texashedgeem/DotNetHedgeEmClient
/
frm_facebook_canvas.aspx.cs
1381 lines (1131 loc) · 57.5 KB
/
frm_facebook_canvas.aspx.cs
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.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web.Services;
using System.Net.Mail;
using System.Text;
using System.Web.Configuration;
using HedgeEmClient;
using System.Runtime.Serialization.Json;
using System.Net;
public partial class frm_facebook_canvas : System.Web.UI.Page
{
private static String logger_name_as_defined_in_app_config = "client." +
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString();
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(logger_name_as_defined_in_app_config);
//Comment added by jaspreet
String my_username = "";
int playerid;
Double xxxHC_a_opening_balance;
String xxxHC_a_password = "";
String xxxHC_a_full_name = "";
//This should not be a global variable [_xxx_log_event]
HedgeEmLogEvent _xxx_log_event = new HedgeEmLogEvent();
int xxxHC_ANON_PLAYER_ID = 100;
string xxxHC_ANON_USERNAME = "admin@mantura.com";
static string ConvertStringArrayToStringJoin(string[] array)
{
//
// Use string Join to concatenate the string elements.
//
string result = string.Join(",", array);
return result;
}
private static string p_current_json_webservice_url_base
{
get
{
return WebConfigurationManager.AppSettings["hedgeem_server_default_webservice_url"].ToString();
}
}
protected void Page_PreInit(object sender, EventArgs e)
{
//this.Page.Theme = "ONLINE";
}
protected void Page_Load(object sender, EventArgs e)
{
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_message = "Method called.";
log.Debug(my_log_event.ToString());
p_session_current_table_id = 1000;
p_session_server_id = 10;
try
{
string strUserAgent = Request.UserAgent.ToString().ToLower();
bool MobileDevice = Request.Browser.IsMobileDevice;
if (Request.Cookies["MobileDevice"] != null)
{
if (Request.Cookies["MobileDevice"].Value == "IgnoreMobile") { MobileDevice = false; }
}
else
{
if (strUserAgent != null)
{
//if (MobileDevice == true || strUserAgent.Contains("iphone") || strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
//strUserAgent.Contains("android") || strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") || strUserAgent.Contains("palm"))
if (strUserAgent.Contains("iphone"))
{
Response.Redirect("https://itunes.apple.com/gb/app/texas-hedgeem/id1018941577?mt=8");
}
}
}
//Read more: http://www.thecodingguys.net/blog/asp-net-mobile-detection#ixzz3qoYVKpHs
if (Request.QueryString["un"] != null && Request.QueryString["p"] != null)
{
string retrieved_username = Decryptdata(Request.QueryString["un"].ToString());
string retrieved_password = Decryptdata(Request.QueryString["p"].ToString());
string retrieved_displayname = Decryptdata(Request.QueryString["dn"].ToString());
Session["p_session_username"] = retrieved_username;
Session["password"] = retrieved_password;
Session["display_name"] = retrieved_displayname;
// service.f_activate_user(retrieved_username);
// my_log_event.p_message = String.Format("Username [{0}] activated. ", retrieved_username);
my_log_event.p_message = String.Format("User [{0}] clicked on link activation. ", retrieved_username);
ScriptManager.RegisterStartupScript(Page, GetType(), "OnLoad", "alert('Thanks for verifying your account. You can now play the game.'); if(alert){ window.location='frm_facebook_canvas.aspx';}", true);
log.Debug(my_log_event.ToString());
}
if (Page.IsPostBack == false)
{
if (Request.QueryString["signout"] != "true")
{
Page.RegisterStartupScript("OnLoad", "<script>document.getElementById('element').style.display='block';</script>");
Page.RegisterStartupScript("OnLoad2", "<script> $('#element').introLoader({animation: { name: 'counterLoader', options: { exitFx: 'slideRight',ease: 'easeOutSine',style: 'fluoYellow', delayBefore: 1000, exitTime: 500, animationTime: 1000} } });</script>");
//#region load_all_images_at_once
////Get Path of Images
//var path = Server.MapPath("~/resources/cards/");
//string[] images = Directory.GetFiles(path, "*.png");
//List<string> get_list_of_images = new List<string>();
//foreach (string image in images)
//{
// string name = Path.GetFileName(image);
// // Add image names in list
// get_list_of_images.Add("'resources/cards/" + name + "'");
//}
//// convert list to array
//string[] array_of_images = get_list_of_images.ToArray();
//// convert array to string along with joining with ','
//string images_ = ConvertStringArrayToStringJoin(array_of_images);
//// script to call the Progress Bar while images are loading
//Page.RegisterStartupScript("Loading", "<script type='text/javascript'> var myImages = [" + images_ + "]; progressBar(myImages.length); </script>");
//// script to load all images
//Page.RegisterStartupScript("Prefetch Images", "<script type='text/javascript'> var myImages = [" + images_ + "]; for (var i = 0; i <= myImages.length; i++) { var img = new Image(); img.src = myImages[i];}</script>");
//#endregion load_all_images_at_once
}
}
else
{
//Page.RegisterStartupScript("OnLoad", "<script>document.getElementById('progressbar').style.display='none';</script>");
}
if (Request.QueryString["r"] != null)
{
my_log_event.p_message = String.Format("Session Timedout message shown to user.");
log.Debug(my_log_event.ToString());
Page.RegisterStartupScript("Alert Message", "<script type='text/javascript'>show_session_timeout_message();</script>");
}
else
{
if (Request.QueryString["action"] != null)
{
Response.Clear();
Session.Abandon();
Response.Redirect("frm_facebook_canvas.aspx");
}
if (Session["p_session_username"] != null)
{
//Page.RegisterStartupScript("OnLoading", "<script>load_edit_profile();</script>");
if (Session["display_name"] != null)
{
}
HedgeEmPlayer my_player = get_player_details(Session["p_session_username"].ToString());
string role = "";
if (my_player != null)
{
role = my_player.p_role;
//my_log_event.p_message = String.Format("User/player role hardcoded to BASIC_USER");
//log.Debug(my_log_event.ToString());
my_log_event.p_message = String.Format("User/player role determined to be [{0}].", role.ToString());
log.Debug(my_log_event.ToString());
}
Session["user_role"] = role;
//// - xxx- Hardcoding value of role to BASIC_USER as need to discuss this with Simon.
//Session["user_role"] = "BASIC_USER";
Page.RegisterStartupScript("OnLoad", "<script>document.getElementById('progressbar').style.display='none';</script>");
}
}
}
catch (Exception ex)
{
HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
my_popup_message.p_detailed_message_str = "";
my_popup_message.p_is_visible = false;
string my_error_popup = "Error in Page Load of frm_facebook_canvas - " + ex.Message.ToString();
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
my_popup_message.p_detailed_message_str = my_error_popup.ToString();
my_popup_message.p_is_visible = true;
Place_Holder_Popup_Message.Controls.Add(my_popup_message);
my_log_event.p_message = "Exception caught in Page Load of frm_facebook_canvas- " + ex.Message;
log.Error(my_log_event.ToString(), new Exception(ex.Message));
}
}
// Method to get details of Player from JSON Web Service
public HedgeEmPlayer get_player_details(string username)
{
HedgeEmPlayer my_player = null;
log.Debug("get_player_details called for getting details of user - " + username);
string my_endpoint = "Not Set";
try
{
my_endpoint = String.Format("{0}/ws_get_player_list/sessionabc123,10,10000/", p_current_json_webservice_url_base);
List<HedgeEmPlayer> my_player_list = (List<HedgeEmPlayer>)f_get_object_from_json_call_to_server(my_endpoint, typeof(List<HedgeEmPlayer>));
foreach (HedgeEmPlayer player in my_player_list)
{
if (player.p_username == username)
{
my_player = player;
return my_player;
}
else
{
my_player = null;
}
}
}
catch (Exception ex)
{
log.Error("Exception in get_player_details() function, - " + ex.Message);
//string my_error_popup = "alert('Error in method [get_player_details] - " + ex.Message.ToString() + "');";
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
my_popup_message.p_detailed_message_str = "";
my_popup_message.p_is_visible = false;
string my_error_popup = "Error in method [get_player_details] - " + ex.Message.ToString();
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
my_popup_message.p_detailed_message_str = my_error_popup.ToString();
my_popup_message.p_is_visible = true;
Place_Holder_Popup_Message.Controls.Add(my_popup_message);
//hedgeem_control_popup_message my_popup_message = new hedgeem_control_popup_message();
//my_popup_message.p_detailed_message_str = "";
//my_popup_message.p_detailed_message_str = ex.Message;
//my_popup_message.p_is_visible = true;
////newuser.Visible = false;
//Place_Holder_Popup_Message.Controls.Add(my_popup_message);
//my_popup_message.Dispose();
}
return my_player;
}
// Method to get details of Table from JSON Web Service
public HedgeEmTableSummary get_table_details(string username)
{
HedgeEmTableSummary my_table = null;
log.Debug("get_table_details called for getting details of table for user - " + username);
string my_endpoint = "Not Set";
try
{
string my_table_name = username;
my_endpoint = String.Format("{0}/get_server_info/10/", p_current_json_webservice_url_base);
List<HedgeEmTableSummary> my_table_list = (List<HedgeEmTableSummary>)f_get_object_from_json_call_to_server("ws_get_hedgeem_table_list/sessionabc123,10,10000/", typeof(List<HedgeEmTableSummary>));
foreach (HedgeEmTableSummary table in my_table_list)
{
if (table.p_table_name == my_table_name)
{
my_table = table;
return my_table;
}
else
{
my_table = null;
}
}
}
catch (Exception ex)
{
//string my_error_popup = "alert('Error in method [get_table_details] - " + ex.Message.ToString() + "');";
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
my_popup_message.p_detailed_message_str = "";
my_popup_message.p_is_visible = false;
string my_error_popup = "Error in method [get_table_details]- " + ex.Message.ToString();
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
my_popup_message.p_detailed_message_str = my_error_popup.ToString();
my_popup_message.p_is_visible = true;
Place_Holder_Popup_Message.Controls.Add(my_popup_message);
log.Error("Exception in get_table_details() function, - " + ex.Message);
}
return my_table;
}
protected void f_login_anonymously(int a_player_id)
{
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
// Log the fact this method has been called
my_log_event.p_message = String.Format("Method [btn_login_Click] called ");
log.Debug(my_log_event.ToString());
string my_endpoint = "Not Set";
// Declare vairibles that will be required later
string my_username = "";
string my_password = "";
DataTable my_user_details;
try
{
// Attempt to retrieve a Player object from the HedgeEm Webservice using the credentials supplied.
my_endpoint = String.Format("{0}/ws_login/{1},{2},{3},{4}/", p_current_json_webservice_url_base, p_session_id, p_session_server_id, my_username, my_password);
HedgeEmPlayer my_player = (HedgeEmPlayer)f_get_object_from_json_call_to_server(my_endpoint, typeof(HedgeEmPlayer));
if (my_player == null)
{
string my_error_msg = String.Format("Player object is null after call to Webservice to retrieve details", my_username);
my_log_event.p_message = my_error_msg;
log.Error(my_log_event.ToString());
throw new Exception(my_error_msg);
}
if (my_player.p_player_id <= 0)
{
my_log_event.p_message = my_player.p_error_message;
log.Error(my_log_event.ToString());
throw new Exception(my_log_event.ToString());
}
else
{
// If we have got here the user has logged into the server sucessfully so we should set some session variables for ease of use later
int my_player_id = my_player.p_player_id;
Session["p_session_player_id"] = my_player_id;
Session["display_name"] = my_player.p_display_name;
Session["p_session_username"] = my_username;
Session["password"] = my_password;
Session["user_role"] = my_player.p_role;
p_session_personal_table_id = my_player.p_personal_table_id;
string role = "";
if (my_player != null)
{
role = my_player.p_role;
my_log_event.p_message = String.Format("User/player role determined to be [{0}].", role.ToString());
log.Debug(my_log_event.ToString());
}
}
}
catch (Exception ex)
{
string my_error_message = "Fatal Errorin method [btn_login_Click] - " + ex.Message.ToString() + "');";
// Log the error and raise a new exception
my_log_event.p_message = String.Format(
"Fatal error in method [btn_login_Click]. Reason [{0}]",
ex.Message);
log.Error(my_log_event.ToString(), new Exception(ex.Message));
HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
my_popup_message.p_detailed_message_str = "";
my_popup_message.p_is_visible = false;
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
my_popup_message.p_detailed_message_str = my_error_message.ToString();
my_popup_message.p_is_visible = true;
Place_Holder_Popup_Message.Controls.Add(my_popup_message);
}
}
/// <summary>
///
/// </summary>
/// <param name="endpoint">Full path to JSON endpoint including base URL. Example: http://devserver.hedgeem.com/Service1.svc/get_server_info/10/</param>
/// <param name="typeIn"></param>
/// <returns></returns>
public static object f_get_object_from_json_call_to_server(string endpoint, Type typeIn)
{
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_message = String.Format("Method called with endpoint [{0}]", endpoint); ;
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
object obj = null;
//my_log.p_player_id = playerid;
try
{
log.Debug(my_log_event.ToString());
HttpWebRequest request;
String my_service_url = "not set";
//my_service_url = WebConfigurationManager.AppSettings["hedgeem_server_default_webservice_url"];
my_log_event.p_message = String.Format("Webservice configured for GoDaddy Deployment URI = [{0}]", endpoint); ;
log.Debug(my_log_event.ToString());
//request = WebRequest.Create(my_service_url + endpoint) as HttpWebRequest;
request = WebRequest.Create(endpoint) as HttpWebRequest;
// Get response
if (request != null)
using (var response = request.GetResponse() as HttpWebResponse)
{
if (response != null)
{
Stream stream = response.GetResponseStream();
if (stream != null)
{
var reader = new StreamReader(stream);
try
{
string json = reader.ReadToEnd();
// Check if stream is empty, if it is throw and exception
if (json.Length == 0)
{
String my_error_msg = String.Format("JSON string has been returned empty for URI endpoint [{0}]", request.Address);
my_log_event.p_message = my_error_msg;
log.Error(my_log_event.ToString());
throw new Exception(my_error_msg);
}
var ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
if (typeIn != null)
{
var ser = new DataContractJsonSerializer(typeIn);
obj = ser.ReadObject(ms);
}
else
{
obj = json;
}
}
finally
{
reader.Close();
}
}
}
}
return obj;
}
catch (System.Net.WebException webex)
{
HttpWebResponse my_error_response = webex.Response as HttpWebResponse;
switch (my_error_response.StatusCode)
{
case HttpStatusCode.BadRequest:
my_log_event.p_message = String.Format(
"Error (Web Exception: BadRequest). Endpoint URI probably badly formed ...\nEndpoint [{0}], Status Code [{1}]",
endpoint,
my_error_response.StatusCode
);
break;
case HttpStatusCode.NotFound:
my_log_event.p_message = String.Format(
"Error (Web Exception: NotFound). Endpoint URI not found; Endpoint [{0}], Status Code [{1}]",
endpoint,
my_error_response.StatusCode
);
break;
default: my_log_event.p_message = String.Format(
"Error unexpected status code (Web Exception of type Status Code [{0}] for Endpoint [{1}], ",
my_error_response.StatusCode,
endpoint
);
break;
}
return new WebException(my_log_event.ToString(), webex);
}
catch (Exception ex)
{
// Log the error and raise a new exception
if (ex.InnerException != null)
{
my_log_event.p_message = String.Format(
"Error. Details [{0}], Inner Exception [{1}]",
ex.Message, ex.InnerException.Message
);
}
else
{
my_log_event.p_message = String.Format(
"Error. Details [{0}]", ex.Message);
}
log.Error(my_log_event.ToString());
//throw new Exception(my_log_event.ToString());
return new Exception(my_log_event.ToString());
}
}
private void f_goto_table(int a_table_id)
{
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_message = "Method Entered";
my_log_event.p_server_id = 4663662;
my_log_event.p_table_id = a_table_id;
my_log_event.p_player_id = p_session_player_id;
log.Debug(my_log_event.ToString());
/* Get reference to table by this table id
For this GUI to work we need a HedgeEMTable object that it will obtain its data from (e.g. cards to display,
odds for each hand etc). So create a place-holder object that we will set later. */
string my_endpoint = "Not Set";
try
{
if (p_valid_session_exists)
{
HedgeemThemeInfo my_hedgeem_theme_info = new HedgeemThemeInfo();
bool xxxHC_my_get_theme_info_from_server_definition = false;
string theme_name = enum_theme.ONLINE.ToString();
if (xxxHC_my_get_theme_info_from_server_definition){
my_endpoint = String.Format("{0}/ws_get_theme_details_for_hedgeem_table/{1}/", p_current_json_webservice_url_base, a_table_id);
my_hedgeem_theme_info = (HedgeemThemeInfo)f_get_object_from_json_call_to_server(my_endpoint, typeof(HedgeemThemeInfo));
if (my_hedgeem_theme_info == null)
{
throw new Exception(String.Format("Unable to determine theme for table [{0}]", a_table_id));
}
if (my_hedgeem_theme_info._error_message != "")
{
throw new Exception(my_hedgeem_theme_info._error_message);
}
theme_name = my_hedgeem_theme_info.short_name;
Session["theme"] = theme_name;
}
// xxx Note from Simon Jan 2015 - not sure what this next line does. If it is just a pop up it can be deleted (esp as it does not work anyway)
//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('" + "Theme name -" + Session["theme"].ToString() + "');", true);
my_log_event.p_message = String.Format("Successfully retrieved theme for table ID [{0}] Theme [{1}] so redirecting to (opening) HedgeEmTable page so ASP can render page to this theme.", a_table_id, theme_name);
log.Debug(my_log_event.ToString());
Response.Redirect("frm_hedgeem_table.aspx", false);
}
else
{
Page.RegisterStartupScript("OnLoad", "<script>alert('You need to be logged in to sit at this table');</script>");
}
}
catch (Exception ex)
{
// xxx_eh error not show to user
string my_error_popup = "alert('Error in method [f_goto_table] - " + ex.Message.ToString() + "');";
// ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
my_log_event.p_message = String.Format("Error", ex.Message);
log.Error(my_log_event.ToString());
//throw new Exception(my_log_event.ToString());
HedgeemerrorPopup my_popup_message = new HedgeemerrorPopup();
my_popup_message.p_detailed_message_str = "";
my_popup_message.p_detailed_message_str = my_error_popup;
my_popup_message.p_is_visible = true;
//newuser.Visible = false;
Place_Holder_Popup_Message.Controls.Add(my_popup_message);
my_popup_message.Dispose();
}
}
private string p_session_username
{
get
{
if (Session["p_session_username"] == null)
{
return "Anonymous";
}
if (Session["p_session_username"] == "")
{
return "Anonymous";
}
return Session["p_session_username"].ToString();
}
set { Session["p_session_username"] = value; }
}
private int p_session_current_table_id
{
get
{
int my_table_id = -1;
try
{
my_table_id = Convert.ToInt32(Session["p_session_current_table_id"]);
}
catch (Exception e)
{
my_table_id = -1;
}
return my_table_id;
}
set { Session["p_session_current_table_id"] = value; }
}
private int p_session_personal_table_id
{
get
{
int my_table_id = -1;
try
{
my_table_id = Convert.ToInt32(Session["p_session_personal_table_id"]);
}
catch (Exception e)
{
my_table_id = -1;
}
return my_table_id;
}
set { Session["p_session_personal_table_id"] = value; }
}
private static string p_session_id
{
get { return HttpContext.Current.Session.SessionID; }
}
private int p_session_player_id
{
get
{
int my_player_id = -1;
try
{
my_player_id = Convert.ToInt32(Session["p_session_player_id"]);
}
catch (Exception e)
{
my_player_id = -1;
}
return my_player_id;
}
set { Session["p_session_player_id"] = value; }
}
private int p_session_server_id
{
get
{
int my_session_server_id = -1;
try
{
my_session_server_id = Convert.ToInt32(Session["p_session_server_id"]);
}
catch (Exception e)
{
my_session_server_id = -1;
}
return my_session_server_id;
}
set { Session["p_session_server_id"] = value; }
}
/// <summary>
/// There are a number of key session variables that need to be set after login that enbles full gameplay as listed below.
/// If all of these are set then 'p_valid_session_exists' returns as TRUE.
/// </summary>
private bool p_valid_session_exists
{
get
{
if (Session["p_session_username"] == null)
{
return false;
}
if (Session["p_session_username"] == "")
{
return false;
}
if (Session["p_session_personal_table_id"] == "")
{
return false;
}
if (Session["p_session_current_table_id"] == "")
{
return false;
}
if (Session["p_session_player_id"] == "")
{
return false;
}
return true;
}
}
/// <summary>
/// WARNING OF DUPLICACTE CODE - See btn_anon_casino_Click, btn_anon_online_Click, and btn_anon_retro_Click
/// only difference is theme selected
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_anon_retro_Click(object sender, EventArgs e)
{
// Log that the user has clicked the 'Play now' button.
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_table_id = p_session_personal_table_id;
my_log_event.p_server_id = p_session_server_id;
my_log_event.p_message = String.Format("User [{0}] clicked 'Play RETRO Anonymously", p_session_username);
log.Info(my_log_event.ToString());
Session["theme"] = enum_theme.RETRO.ToString();
try
{
f_play_anon(enum_theme.RETRO);
}
catch (Exception ex)
{
my_log_event.p_message = String.Format("Error user try to play Anonymously using RETRO Theme. Reason [{0}]", ex.Message);
log.Error(my_log_event.ToString());
// Cant throw a exception here
//throw new Exception(my_log_event.ToString());
}
}
/// <summary>
/// WARNING OF DUPLICACTE CODE - See btn_anon_casino_Click, btn_anon_online_Click, and btn_anon_retro_Click
/// only difference is theme selected
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_anon_online_Click(object sender, EventArgs e)
{
// Log that the user has clicked the 'Play now' button.
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_table_id = p_session_personal_table_id;
my_log_event.p_server_id = p_session_server_id;
my_log_event.p_message = String.Format("User [{0}] clicked 'Play ONLINE Anonymously", p_session_username);
log.Info(my_log_event.ToString());
try
{
f_play_anon(enum_theme.ONLINE);
}
catch (Exception ex)
{
my_log_event.p_message = String.Format("Error user try to play Anonymously using ONLINE Theme. Reason [{0}]", ex.Message);
log.Error(my_log_event.ToString());
// Cant throw a exception here
//throw new Exception(my_log_event.ToString());
}
}
/// <summary>
/// WARNING OF DUPLICACTE CODE - See btn_anon_casino_Click, btn_anon_online_Click, and btn_anon_retro_Click
/// only difference is theme selected
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_anon_casino_Click(object sender, EventArgs e)
{
// Log that the user has clicked the 'Play now' button.
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_table_id = p_session_personal_table_id;
my_log_event.p_server_id = p_session_server_id;
my_log_event.p_message = String.Format("User [{0}] clicked 'Play Casino Anonymously", p_session_username);
log.Info(my_log_event.ToString());
try
{
f_play_anon(enum_theme.CASINO);
}
catch (Exception ex)
{
my_log_event.p_message = String.Format("Error user try to play Anonymously using CASINO Theme. Reason [{0}]", ex.Message);
log.Error(my_log_event.ToString());
// Cant throw a exception here
//throw new Exception(my_log_event.ToString());
}
}
protected void f_play_anon(enum_theme a_enum_theme)
{
// Log that the user has clicked the 'Play now' button.
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_table_id = p_session_personal_table_id;
my_log_event.p_server_id = p_session_server_id;
my_log_event.p_message = String.Format("User [{0}] click 'Play Now", p_session_username);
log.Info(my_log_event.ToString());
// This fucntion should not be able to be played if the player as not logged in, so test if they have
// a 'HedgeEm Session' has been established, If not exit this fucntion.
/*if (!p_valid_session_exists)
{
my_log_event.p_message = String.Format("User informed the session is invalide.");
log.Debug(my_log_event.ToString());
//ScriptManager.RegisterStartupScript(Page, GetType(), "Alert Message", "alert('You must be logged in to Play this game.');", true);
ScriptManager.RegisterStartupScript(Page, GetType(), "Alert Message", "document.getElementById('alertmessage').style.display = 'block';", true);
return;
}*/
// xxx Consider uncommenting the following after aslo considering consequence (if you do this when user clicks leave table
// they will leave there personal table which you may not want currently as the code currently (Dec 2014) assumes you are sitting at
// personal table all the time.
HedgeEmPlayer my_hedgeem_player;
//my_hedgeem_player = f_get_free_anonymous_player();
DC_hedgeem_game_state my_game_state = f_sit_at_anonymous_table(a_enum_theme);
//f_login_anonymously(1201);
if (my_game_state.p_error_message != null)
{
if (my_game_state.p_error_message != "")
{
throw new Exception(my_game_state.p_error_message);
}
}
Session["p_session_username"] = my_game_state._seats[0].p_player_name;
Session["p_session_personal_table_id"] = my_game_state.p_table_id;
Session["p_session_current_table_id"] = my_game_state.p_table_id;
Session["p_session_player_id"] = my_game_state._seats[0].p_player_id;
Session["theme"] = a_enum_theme.ToString();
Session["role"] = "BASIC_USER";
f_goto_table(my_game_state.p_table_id);
// If code reaches here we asssume Table ID and PlayerID is known so sit the person at this table
}
protected string f_get_facebook_app_id()
{
String my_app_id = ConfigurationManager.AppSettings["hedgeem_facebook_app_id"];
return my_app_id;
}
// Web Method to check the role of the logged in user. Called when Facebook SDK is rendered and user is logged in.
[WebMethod(EnableSession = true)]
public static string f_check_user_role()
{
log.Debug("f_check_user_role called to check the role of the user.");
string role = "";
try
{
// Fetch the email from Javascript through query string
string email = HttpContext.Current.Request.QueryString["uid"].ToString();
if (email != "")
{
string my_endpoint1 = String.Format("{0}/ws_get_password_from_db/{1}/", p_current_json_webservice_url_base,
email);
DataTable dt = (DataTable)f_get_object_from_json_call_to_server(my_endpoint1, typeof(DataTable));
// DataTable dt = service.f_get_password_from_db(email);
if (dt.Rows.Count > 0)
{
string password = dt.Rows[0]["password"].ToString();
string my_endpoint = String.Format("{0}/ws_my_user_details/{1},{2}/", p_current_json_webservice_url_base,
email,
password);
DataTable userdetails = (DataTable)f_get_object_from_json_call_to_server(my_endpoint, typeof(DataTable));
// DataTable userdetails = service.my_user_details(email, password);
role = userdetails.Rows[0]["role"].ToString();
}
HttpContext.Current.Session["user_role"] = role;
}
return role;
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in method [f_check_user_role] - " + ex.Message.ToString() + "');";
//System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>" + my_error_popup + "</SCRIPT>");
log.Error("Error in f_check_user_role", new Exception(ex.Message));
return my_error_popup;
}
}
private static int p_server_id
{
get
{
int my_server_id = Convert.ToInt32(ConfigurationManager.AppSettings["default_hedgeem_server_id"]);
return my_server_id;
}
}
/// <summary>
/// Added by Simon on 1 Dec 2014 not really knowing what I am doing but copying existing code. Called when Facebook SDK is rendered and user is logged in.
/// This is called by the Javascript function when it has detemined that a user is authenticated against facebook ID. I should then use this to actually
/// log in to the HedgeEm Server.
/// Method must be STATIC
/// Last edited 4 Jan 2015 (Commented out throw new exception when user not found.
/// I believe the only purpose of this method is to call the hedgeem webservice login function when the user authenticates with facebook.
/// </summary>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public static string f_facebook_login_called_from_javascript()
{
log.Warn("WANRING - COPIED NOT USED f_check_user_role called to check the role of the user.");
string role = "Herman";
string email = HttpContext.Current.Request.QueryString["uid"].ToString();
hedgeem_control_popup_message my_popup_message = new hedgeem_control_popup_message();
my_popup_message.p_detailed_message_str = "";
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
// Log the fact this method has been called
my_log_event.p_message = String.Format("Method [btn_login_Click] called ");
log.Debug(my_log_event.ToString());
my_log_event.p_method_name = System.Reflection.MethodBase.GetCurrentMethod().ToString();
my_log_event.p_message = "This message creates new fb user in database";
string my_endpoint = "Not Set";