forked from texashedgeem/DotNetHedgeEmClient
/
frm_home_page.aspx.cs
3303 lines (2998 loc) · 163 KB
/
frm_home_page.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.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using System.Media;
using System.Data;
using System.Text;
using System.Web.Services;
using HedgeEmClient;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Web.Configuration;
using System.Threading;
public partial class frm_home_page : System.Web.UI.Page
{
#region Controls
hedgeem_control_card cc_flop_card1;
hedgeem_control_card cc_flop_card2;
hedgeem_control_card cc_flop_card3;
hedgeem_control_card cc_turn_card;
hedgeem_control_card cc_river_card;
hedgeem_control_seats ss_seat;
hedgeem_hand_panel[] _hedgeem_hand_panels;
BETTING_PANEL[,] _hedgeem_betting_panels;
#endregion
int _xxxHCnumber_of_hands = 4;
int _table_id;
int _xxxHCnumber_of_seats = 1; // xxx_HC value
Double xxxHC_a_opening_balance;
String xxxHC_a_password = "";
String xxxHC_a_full_name = "";
int chk_admin_flag_value = 0;
enum_game_state _game_state;
double my_jackpot_fund;
string p_flop_card1_as_short_string;
string p_flop_card2_as_short_string;
string p_flop_card3_as_short_string;
string p_turn_as_short_string;
string p_river_as_short_string;
int game_id;
enum_theme my_default_theme;
string p_game_status_as_json_string;
String p_odds_percent_win_or_draw_string;
String p_odds_percent_win_string;
String p_odds_percent_draw_string;
String p_odds_actual_string;
double p_odds_percent_win_or_draw_double;
double p_odds_actual_double;
double p_odds_margin;
double xxxp_odds_margin_rounded;
double p_presented_margin;
int _int_number_of_betting_stages;
WebClient wc = new WebClient();
double player_funds_at_seat;
int p_total_bets;
string p_hand_card1;
string p_hand_card2;
enum_hand_in_play_status p_inplay_status;
enum_acknowledgement_type p_ack_type;
string _bet_value;
int xxx_HC_seat_index = 0;
localhost.WebService service = new localhost.WebService();
HedgeEmLogEvent _xxx_log_event = new HedgeEmLogEvent();
int playerid;
//For Logging
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);
DC_hedgeem_game_state _global_game_state_object = new DC_hedgeem_game_state();
// preinit event changes the theme of the page at runtime before page loads
protected void Page_PreInit(object sender, EventArgs e)
{
HedgeEmLogEvent my_log_event = new HedgeEmLogEvent();
my_log_event.p_method_name = "frm_home_page.aspx.cs-Page_PreInit";
my_log_event.p_message = "Method called";
log.Debug(my_log_event.ToString());
//ThreadStart tsTask = new ThreadStart(TaskLoop);
//Thread MyTask = new Thread(tsTask);
//MyTask.Start();
try
{
if (Session["theme"] == null)
{
my_log_event.p_message = "Warning - hard coding of theme to ONLINE (should never get here)";
log.Warn(my_log_event.ToString());
Session["theme"] = "ONLINE";
this.Page.Theme = this.Page.Theme = Session["theme"].ToString();
}
else
{
// this changes the theme of the hedgeem table according to the theme selected by the user.
this.Page.Theme = Session["theme"].ToString();
if (this.Page.Theme == "") ;
{
// xxxeh - need to throw error when string =""
this.Page.Theme = "ONLINE";
}
}
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in Page PreInit - " + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = ex.Message;
my_log.p_method_name = "Page Load";
my_log.p_player_id = f_get_player_id();
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
}
// method to get values from SVC web service when required
private object f_get_object_from_json_call_to_server(string endpoint, Type typeIn)
{
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = String.Format("Method called with endpoint [{0}]", endpoint); ;
my_log.p_method_name = "f_get_object_from_json_call_to_server";
my_log.p_player_id = f_get_player_id();
my_log.p_table_id = _table_id;
log.Debug(my_log.ToString());
object obj = null;
HttpWebRequest request;
String my_service_url = "not set";
Boolean my_use_localhost_webservice = Convert.ToBoolean(WebConfigurationManager.AppSettings["use_localhost_webservice"]);
my_log.p_message = String.Format("WARNING! If a exception happens in this function is does not appear to user.");
log.Warn(my_log.ToString());
if (my_use_localhost_webservice == true)
{
// Create the web request
my_service_url = "http://localhost:59225/Service1.svc/";
my_log.p_message = String.Format("Webservice configured for local development URI = [{0}{1}]", my_service_url, endpoint); ;
}
else
{
my_service_url = "http://devserver.hedgeem.com/Service1.svc/";
my_log.p_message = String.Format("Webservice configured for GoDaddy Deployment URI = [{0}{1}]", my_service_url, endpoint); ;
}
log.Debug(my_log.ToString());
request = WebRequest.Create(my_service_url + 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.p_message = my_error_msg;
log.Error(my_log.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;
}
protected void Page_Load(object sender, EventArgs e)
{
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "frm_home_page.aspx.cs method called.";
my_log.p_method_name = "Page_Load";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Debug(my_log.ToString());
try
{
// checks if session is timed out
if (Session.Count == 0)
{
Page.RegisterStartupScript("Alert Message", "<script type='text/javascript'>show_session_timeout_message();</script>");
}
else
{
my_log.p_message = "Warning: Hardcoding of table ID";
log.Warn(my_log.ToString());
int xxx_HC_table_id_for_shared_home_page_table = 1000;
int my_player_id = Convert.ToInt32(Session["playerid"]);
_table_id = xxx_HC_table_id_for_shared_home_page_table;
if (Page.IsPostBack == false)
{
try
{
_global_game_state_object = (DC_hedgeem_game_state)f_get_object_from_json_call_to_server("get_game_state_object/" + _table_id, typeof(DC_hedgeem_game_state));
// _global_game_state_object = (DC_hedgeem_game_state)f_get_object_from_json_call_to_server("get_next_game_state_object/" + _table_id + "," + f_get_player_id(), typeof(DC_hedgeem_game_state));
my_log.p_message = String.Format("Successfully retrieved gamestate from server. Table ID [{0}], State [{1}]", _global_game_state_object.p_table_id, _global_game_state_object.p_current_state_enum.ToString());
log.Debug(my_log.ToString());
}
catch (Exception ex)
{
my_log.p_message = String.Format("Error trying to get game state from server. Reason [{0}]", ex.Message);
log.Error(my_log.ToString());
}
if (Session["user_role"] != null)
{
string role = Session["user_role"].ToString();
// if user is admin, show cashier button
if (role == enum_user_role.ADMIN.ToString())
{
btn_cashier.Visible = true;
}
}
table_jackpot_container.Visible = false;
ScriptManager sManager = ScriptManager.GetCurrent(this.Page);
/*
//Get Image from Facebook if the user is logged in via facebook
string facebook_imageurl = "";
if (Session["Facebook_User_Id"] != "")
{
//Get Image from Facebook
facebook_imageurl = "https://graph.facebook.com/" + Session["Facebook_User_Id"].ToString() + "/picture";
}
if (facebook_imageurl != "")
{
// Get path to save the image
string pathToSave = Server.MapPath("~/resources/") + "player_avatar_" + Session["username"].ToString() + ".jpg";
//Check if the Image exists already
if (!File.Exists(pathToSave))
{
//Save the image
WebClient client = new WebClient();
client.DownloadFile(facebook_imageurl, pathToSave);
}
}
*/
game_id = _global_game_state_object.p_game_id;
int my_number_of_hands = _global_game_state_object.p_number_of_hands_int;
enum_betting_stage my_betting_stage = f_get_current_betting_stage();
_game_state = _global_game_state_object.p_current_state_enum;
_hedgeem_hand_panels = new hedgeem_hand_panel[my_number_of_hands];
// Session["sess_betting_stage_enum"] = _global_game_state_object.p_current_betting_stage_enum;
_int_number_of_betting_stages = _global_game_state_object.p_number_of_betting_stages_int;
_hedgeem_betting_panels = new BETTING_PANEL[_int_number_of_betting_stages, my_number_of_hands];
lbl_game_id.Text = String.Format("Table/Game: {0}/{1} ", _global_game_state_object.p_table_id, game_id);
// gets seat balance of the current player
player_funds_at_seat = _global_game_state_object._seats[0].p_player_seat_balance;
f_call_functions_to_render_screen();
}
// Dynamically contructed the Web page title so show relevant info about Server, Table and Game the player is playing.
// String my_page_title = String.Format("Texas Hedge'Em Poker | Server [{0}], Table {1}], Game [{2}]","server id", p_table_name, p_table_id);
// this.Page.Title = my_page_title;
// Page.RegisterStartupScript("call deal button code", "<script>setInterval('" + btn_deal_next_stage_Click() + "',3000);</script>");
// btn_deal_next_stage_Click();
/*Click on Hand_Panel to get the value of current hand via _click_hand_index and then that value pass to hidden textbox i.e mytext, when Hand_Index_Value is shown in textbox then btn_Get_Clicked_Hand_Value method to get the value of bet that we placed i.e HOLE: £1 bet pays £4*/
Page.RegisterStartupScript("Bet_Placed_Details", "<script>f_placebet(_click_hand_index);</script>");
if (Session["username"] != null)
{
Logout.Attributes.Add("style", "display:block!Important;");
Page.RegisterStartupScript("OnLoading", "<script>load_edit_profile();</script>");
if (Session["display_name"] != null)
{
lbl_user_name.Text = Session["display_name"].ToString();
}
LoginDiv.Attributes.Add("style", "display:none !Important;");
usr_image.ImageUrl = "../resources/player_avatar_" + Session["username"].ToString() + ".jpg";
btn_play_now.Enabled = true;
// check user role
DataTable dt = service.f_get_password_from_db(Session["username"].ToString());
string role = "";
if (dt.Rows.Count > 0)
{
string password = dt.Rows[0]["password"].ToString();
DataTable userdetails = service.my_user_details(Session["username"].ToString(), password);
role = userdetails.Rows[0]["role"].ToString();
}
if (role == enum_user_role.ADMIN.ToString())
{
btnAdmin.Visible = true;
}
Session["user_role"] = role;
Page.RegisterStartupScript("OnLoad", "<script>document.getElementById('progressbar').style.display='none';</script>");
}
}
}
//catch (FaultException<Exception_Fault_Contract> ex)
//{
//}
catch (Exception ex)
{
//string my_error_popup = "alert('Error in Page Load - " + ex.Message.ToString() + "');";
string my_error_popup = "Major Error in Page_load";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
log.Error(my_log.ToString());
//throw new Exception(my_error_popup);
}
}
protected void btnAdmin_Click(object sender, EventArgs e)
{
log.Info("User clicked on Admin Button");
try
{
if (txt_get_fm_email_id.Text == "")
{
Page.RegisterStartupScript("Alert Message", "<script type='text/javascript'>alert('You are not logged in. Please log in to view this Page.');document.getElementById('progressbar').style.display='none'; </script>");
}
else
{
DataTable get_password = new DataTable();
DataTable user_details = new DataTable();
get_password = service.f_get_password_from_db(txt_get_fm_email_id.Text);
if (get_password.Rows.Count == 0)
{
Page.RegisterStartupScript("Alert Message", "<script type='text/javascript'>alert('You are not authorized to view this page.');</script>");
}
else
{
string password = get_password.Rows[0]["password"].ToString();
user_details = service.my_user_details(txt_get_fm_email_id.Text, password);
// Check you got only one record back, if not throw appropriate exception
if (user_details.Rows.Count < 1)
{
throw new Exception(String.Format("Username '{0}' not found. Username or password incorrect.", txt_get_fm_email_id.Text));
}
else if (user_details.Rows.Count > 1)
{
throw new Exception(String.Format("Multiple users found for username '{0}'. This indicates something is wrong so cancelling operation..", txt_get_fm_email_id.Text));
}
else
{
enum_user_role role = (enum_user_role)Enum.Parse(typeof(enum_user_role), user_details.Rows[0]["role"].ToString());
if (role == enum_user_role.ADMIN)
{
Response.Redirect("http://serveradmin.hedgeem.com");
}
else
{
Page.RegisterStartupScript("Alert Message", "<script type='text/javascript'>alert('You are not authorized to view this page.');</script>");
}
}
}
}
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in method [btnAdmin_Click] - " + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
log.Error("Error in btnAdmin_Click", new Exception(ex.Message));
}
}
#region Sound_Play_On_Click_Of_Deal_Button
// This function plays sound on the click of deal button
private void PlaySound()
{
log.Debug("PlaySound method of Hedgeem Table is called");
try
{
SoundPlayer sd = new SoundPlayer();
sd.SoundLocation = Server.MapPath("~/resources/waves/Deal-4.wav");
sd.Play();
sd.Play();
sd.Play();
sd.Play();
sd.Play();
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in PlaySound method - " + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = ex.Message;
my_log.p_method_name = "PlaySound";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
}
#endregion Sound_Play_On_Click_Of_Deal_Button
private int f_get_player_id()
{
return 10000;
}
//#region f_activate_deal_hole_button_and_hide_others
//private void f_activate_deal_hole_button_and_hide_others()
//{
// /*----- This function only shown Deal Display Random others are invisible------*/
// btnDealHole.Visible = true;
// btnDealFlop.Visible = false;
// btnDealTurn.Visible = false;
// btnDealRiver.Visible = false;
// btnNextGame.Visible = false;
//}
//#endregion
//#region f_activate_deal_flop_button_and_hide_others
//private void f_activate_deal_flop_button_and_hide_others()
//{
// /*----- This function only shown Deal Flop others are invisible------*/
// btnDealHole.Visible = false;
// btnDealFlop.Visible = true;
// btnDealTurn.Visible = false;
// btnDealRiver.Visible = false;
// btnNextGame.Visible = false;
// btnLobby.Visible = true;
//}
//#endregion
//#region f_activate_deal_turn_button_and_hide_others
//private void f_activate_deal_turn_button_and_hide_others()
//{
// /*----- This function only shown Deal Turn others are invisible------*/
// btnDealHole.Visible = false;
// btnDealFlop.Visible = false;
// btnDealTurn.Visible = true;
// btnDealRiver.Visible = false;
// btnNextGame.Visible = false;
// btnLobby.Visible = true;
//}
//#endregion Visible_Deal_Turn_Buttons
//#region f_activate_deal_river_button_and_hide_others
//private void f_activate_deal_river_button_and_hide_others()
//{
// /*----- This function only shown Deal River others are invisible------*/
// btnDealHole.Visible = false;
// btnDealFlop.Visible = false;
// btnDealTurn.Visible = false;
// btnDealRiver.Visible = true;
// btnLobby.Visible = true;
//}
//#endregion Visible_Deal_River_Buttons
//#region f_activate_deal_next_button_and_hide_others
//private void f_activate_deal_next_button_and_hide_others()
//{
// /*----- This function only shown Deal Next others are invisible------*/
// btnDealHole.Visible = false;
// btnDealFlop.Visible = false;
// btnDealTurn.Visible = false;
// btnDealRiver.Visible = false;
// btnNextGame.Visible = true;
//}
//#endregion Visible_Deal_Next_Buttons
/// Context / Background reading
/// ----------------------------
/// You must understand the following before understanding this function
/// + What the HedgeEmHandStageInfo class is and what its purpose is.
///
/// History
/// -----------
/// Original Author: Simon Hewins Jul 2014
/// Last edit: Simon Hewins Aug 2014
///
/// Description
/// -----------
///
/// Gets a LIST of HedgeEmHandStageInfo objects for any given hand (index) at any given stage.
/// </summary>
/// <param name="a_enum_game_state"></param>
/// <param name="a_hand_index"></param>
/// <returns></returns>
public List<HedgeEmBet> f_get_previous_bets_for_stage_and_hand_player_list(enum_betting_stage a_enum_betting_stage, int a_hand_index, int a_player_id)
{
/// xxx hack until Bet contains player id
a_player_id = 0;
List<HedgeEmBet> my_previous_bets_list = new List<HedgeEmBet>();
try
{
my_previous_bets_list = (from handsstage_objects in _global_game_state_object.p_recorded_bets
where handsstage_objects.p_enum_betting_stage == a_enum_betting_stage
&& handsstage_objects.p_hand_index == a_hand_index
&& handsstage_objects.p_seat_index == a_player_id
select handsstage_objects).ToList();
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in f_get_previous_bets_for_stage_and_hand" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_get_hand_stage_info_object_for_stage_and_hand function " + ex.Message;
my_log.p_method_name = "f_get_hand_stage_info_object_for_stage_and_hand";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
return my_previous_bets_list;
}
/// Context / Background reading
/// ----------------------------
/// You must understand the following before understanding this function
/// + What the HedgeEmHandStageInfo class is and what its purpose is.
///
/// History
/// -----------
/// Original Author: Simon Hewins Jul 2014
/// Last edit: Simon Hewins Aug 2014
///
/// Description
/// -----------
///
/// Gets a LIST of HedgeEmHandStageInfo objects for any given hand (index) at any given stage.
/// </summary>
/// <param name="a_enum_game_state"></param>
/// <param name="a_hand_index"></param>
/// <returns></returns>
public HedgeEmBet f_get_previous_bets_for_stage_and_hand_player(enum_betting_stage a_enum_betting_stage, int a_hand_index, int a_player_id)
{
/// xxx hack until Bet contains player id
a_player_id = 0;
List<HedgeEmBet> my_previous_bets_list = new List<HedgeEmBet>();
HedgeEmBet myHedgeEmBet = null;
try
{
my_previous_bets_list = (from handsstage_objects in _global_game_state_object.p_recorded_bets
where handsstage_objects.p_enum_betting_stage == a_enum_betting_stage
&& handsstage_objects.p_hand_index == a_hand_index
&& handsstage_objects.p_seat_index == a_player_id
select handsstage_objects).ToList();
if (my_previous_bets_list.Count > 1)
{
String my_err_msg = String.Format("Expected only one 'Bet' for state [{0}], hand [{1}] object got [{1}] ",
a_enum_betting_stage.ToString(),
a_hand_index,
my_previous_bets_list.Count);
throw new Exception(my_err_msg);
}
myHedgeEmBet = my_previous_bets_list[0];
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in f_get_previous_bets_for_stage_and_hand" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_get_hand_stage_info_object_for_stage_and_hand function " + ex.Message;
my_log.p_method_name = "f_get_hand_stage_info_object_for_stage_and_hand";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
return myHedgeEmBet;
}
private enum_game_state f_convert_hedgeem_stage_to_state(enum_betting_stage a_betting_stage)
{
enum_game_state my_enum_game_state_HACK = enum_game_state.UNCHANGED;
switch (a_betting_stage)
{
case enum_betting_stage.HOLE_BETS:
my_enum_game_state_HACK = enum_game_state.STATUS_HOLE;
break;
case enum_betting_stage.FLOP_BETS:
my_enum_game_state_HACK = enum_game_state.STATUS_FLOP;
break;
case enum_betting_stage.TURN_BETS:
my_enum_game_state_HACK = enum_game_state.STATUS_TURN;
break;
default:
break;
}
return my_enum_game_state_HACK;
}
/// Context / Background reading
/// ----------------------------
/// You must understand the following before understanding this function
/// + What the HedgeEmHandStageInfo class is and what its purpose is.
///
/// History
/// -----------
/// Original Author: Simon Hewins Jul 2014
/// Last edit: Simon Hewins Aug 2014
///
/// Description
/// -----------
///
/// Gets a LIST of HedgeEmHandStageInfo objects for any given hand (index) at any given stage.
/// </summary>
/// <param name="a_enum_game_state"></param>
/// <param name="a_hand_index"></param>
/// <returns></returns>
public double f_get_total_previous_bets_for_stage_and_hand_player(enum_betting_stage a_enum_betting_stage, int a_hand_index, int a_player_id)
{
/// xxx hack until Bet contains player id
a_player_id = 0;
List<HedgeEmBet> my_previous_bets_list = new List<HedgeEmBet>();
HedgeEmBet myHedgeEmBet = null;
double my_bet_total = -666;
try
{
my_previous_bets_list = (from handsstage_objects in _global_game_state_object.p_recorded_bets
where handsstage_objects.p_enum_betting_stage == a_enum_betting_stage
&& handsstage_objects.p_hand_index == a_hand_index
&& handsstage_objects.p_seat_index == a_player_id
select handsstage_objects).ToList();
my_bet_total = (from handsstage_objects in _global_game_state_object.p_recorded_bets
where handsstage_objects.p_enum_betting_stage == a_enum_betting_stage
&& handsstage_objects.p_hand_index == a_hand_index
&& handsstage_objects.p_seat_index == a_player_id
select handsstage_objects.p_bet_amount).Sum();
/*if (my_previous_bets_list.Count > 1)
{
String my_err_msg = String.Format("Expected only one 'Bet' for state [{0}], hand [{1}] object got [{1}] ",
a_enum_betting_stage.ToString(),
a_hand_index,
my_previous_bets_list.Count);
throw new Exception(my_err_msg);
}*/
//myHedgeEmBet = my_previous_bets_list[0];
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in f_get_previous_bets_for_stage_and_hand" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_get_hand_stage_info_object_for_stage_and_hand function " + ex.Message;
my_log.p_method_name = "f_get_hand_stage_info_object_for_stage_and_hand";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
return my_bet_total;
}
/// <summary>
/// Context / Background reading
/// ----------------------------
/// You must understand the following before understanding this function
/// + What the HedgeEmHandStageInfo class is and what its purpose is.
///
/// History
/// -----------
/// Original Author: Simon Hewins Jul 2014
/// Last edit: Simon Hewins Aug 2014
///
/// Description
/// -----------
///
/// Gets a LIST of HedgeEmHandStageInfo objects for any given hand (index) at any given stage.
/// </summary>
/// <param name="a_enum_game_state"></param>
/// <param name="a_hand_index"></param>
/// <returns></returns>
public HedgeEmHandStageInfo f_get_hand_stage_info_object_for_stage_and_hand(enum_game_state a_enum_game_state, int a_hand_index)
{
List<HedgeEmHandStageInfo> myHedgeEmHandStageInfoList = new List<HedgeEmHandStageInfo>();
HedgeEmHandStageInfo myHedgeEmHandStageInfo = null;
try
{
// Return without searching if not a valid state where a hand_stage_info object is expected.
if (!(a_enum_game_state == enum_game_state.STATUS_HOLE || a_enum_game_state == enum_game_state.STATUS_FLOP || a_enum_game_state == enum_game_state.STATUS_TURN || a_enum_game_state == enum_game_state.STATUS_RIVER))
{
return myHedgeEmHandStageInfo;
}
myHedgeEmHandStageInfoList = (from handsstage_objects in _global_game_state_object.p_hand_stage_info_list
where handsstage_objects.p_enum_game_state == a_enum_game_state
&& handsstage_objects.p_hand_index == a_hand_index
select handsstage_objects).ToList();
if (myHedgeEmHandStageInfoList.Count > 1)
{
String my_err_msg = String.Format("Expected only one 'HandStatusInfo' for state [{0}], hand [{1}] object got [{1}] ",
a_enum_game_state.ToString(),
a_hand_index,
myHedgeEmHandStageInfoList.Count);
throw new Exception(my_err_msg);
}
myHedgeEmHandStageInfo = myHedgeEmHandStageInfoList[0];
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in f_get_hand_stage_info_object_for_stage_and_hand" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_get_hand_stage_info_object_for_stage_and_hand function " + ex.Message;
my_log.p_method_name = "f_get_hand_stage_info_object_for_stage_and_hand";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
throw new Exception(my_error_popup);
}
return myHedgeEmHandStageInfo;
}
/// <summary>
/// Context / Background reading
/// ----------------------------
/// You must understand the following before understanding this function
/// + What the HedgeEmHandStageInfo class is and what its purpose is.
///
/// History
/// -----------
/// Original Author: Simon Hewins Jul 2014
/// Last edit: Simon Hewins Aug 2014
///
/// Description
/// -----------
///
/// Gets a LIST of HedgeEmHandStageInfo objects for any given hand (index) at any given stage.
/// </summary>
/// <param name="a_enum_game_state"></param>
/// <param name="a_hand_index"></param>
/// <returns></returns>
public List<HedgeEmHandStageInfo> f_get_hand_stage_info_object_for_stage_and_hand_list(enum_game_state a_enum_game_state, int a_hand_index)
{
List<HedgeEmHandStageInfo> myHedgeEmHandStageInfo = new List<HedgeEmHandStageInfo>();
try
{
myHedgeEmHandStageInfo = (from handsstage_objects in _global_game_state_object.p_hand_stage_info_list
where handsstage_objects.p_enum_game_state == a_enum_game_state
&& handsstage_objects.p_hand_index == a_hand_index
select handsstage_objects).ToList();
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in f_get_hand_stage_info_object_for_stage_and_hand" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_get_hand_stage_info_object_for_stage_and_hand function " + ex.Message;
my_log.p_method_name = "f_get_hand_stage_info_object_for_stage_and_hand";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
return myHedgeEmHandStageInfo;
}
#region f_place_bet
//This function is used to Maintain Hand Panel Values when Bet is Placed on a Hand.
public void f_place_bet()
{
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = String.Format("Method called. Player [{0}], Table [{1}], Game [{2}]", f_get_player_id(), _table_id, game_id);
my_log.p_method_name = "frm_hedgeem_table.f_place_bet()";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
enum_betting_stage my_betting_stage = (enum_betting_stage)Session["sess_betting_stage_enum"];
log.Debug(my_log.ToString());
/* Get value of Selected_Hand_Panel for bet from textbox and save it in a variable */
try
{
// Get the hand_index from the hidden control
int handindexbet = Convert.ToInt32(btn_hidden_control_temp_store_for_hand_index.Value);
DC_bet_acknowledgement my_bet_ack;
// xxx_HC hardcode the bet value to be £1
int bet_amount = 1;
enum_betting_stage my_betting_stage_enum = (enum_betting_stage)Session["sess_betting_stage_enum"];
my_bet_ack = f_place_bet(my_betting_stage_enum, handindexbet, bet_amount);
if (my_bet_ack.p_ack_or_nak != enum_acknowledgement_type.ACK.ToString())
{
string short_desc = "Bet not accepted because. Reason: ";
//To show error description that why bet is not accepted inside div
short_description.InnerHtml = short_desc + my_bet_ack.p_nak_reason + " Player Id: " + f_get_player_id() + " Stage: " + my_betting_stage;
ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", "document.getElementById('error_message').style.display = 'block';document.getElementById('fade').style.display = 'block';", true);
}
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in frm.hedgeem_table.cs.f_place_bet" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_place_bet function " + ex.Message;
my_log.p_method_name = "f_place_bet";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
}
#endregion f_place_bet
#region f_update_hedgeem_control_buttons_with_info_from_server
private void f_update_hedgeem_control_buttons_with_info_from_server()
{
log.Debug("f_update_hedgeem_control_buttons_with_info_from_server called");
// Determine the new state of the game and display the appropriate buttons
try
{
switch (_game_state)
{
case enum_game_state.STATUS_START:
//btnDealHole.Visible = true;
//btnDealFlop.Visible = false;
//btnDealTurn.Visible = false;
//btnDealRiver.Visible = false;
//btnNextGame.Visible = false;
f_clear_players_bets_lablels();
break;
case enum_game_state.STATUS_HOLE:
//btnDealHole.Visible = false;
//btnDealFlop.Visible = true;
//btnDealTurn.Visible = false;
//btnDealRiver.Visible = false;
//btnNextGame.Visible = false;
break;
case enum_game_state.STATUS_FLOP:
//btnDealHole.Visible = false;
//btnDealFlop.Visible = false;
//btnDealTurn.Visible = true;
//btnDealRiver.Visible = false;
//btnNextGame.Visible = false;
break;
case enum_game_state.STATUS_TURN:
//btnDealHole.Visible = false;
//btnDealFlop.Visible = false;
//btnDealTurn.Visible = false;
//btnDealRiver.Visible = true;
//btnNextGame.Visible = false;
break;
case enum_game_state.STATUS_RIVER:
//btnDealHole.Visible = false;
//btnDealFlop.Visible = false;
//btnDealTurn.Visible = false;
//btnDealRiver.Visible = false;
//btnNextGame.Visible = true;
hedgeem_control_winner_message my_winner_message = new hedgeem_control_winner_message();
my_winner_message.p_winner_message_str = f_calculate_winnings();
if (my_winner_message.p_winner_message_str != "")
{
Place_Holder_Winner_Message.Controls.Add(my_winner_message);
}
break;
default:
//btnDealHole.Visible = false;
//btnDealFlop.Visible = false;
//btnDealTurn.Visible = false;
//btnDealRiver.Visible = false;
//btnNextGame.Visible = true;
break;
}
}
catch (Exception ex)
{
string my_error_popup = "alert('Error in f_update_hedgeem_control_buttons_with_info_from_server" + ex.Message.ToString() + "');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", my_error_popup, true);
HedgeEmLogEvent my_log = new HedgeEmLogEvent();
my_log.p_message = "Exception caught in f_update_hedgeem_control_buttons_with_info_from_server function " + ex.Message;
my_log.p_method_name = "f_update_hedgeem_control_buttons_with_info_from_server";
my_log.p_player_id = f_get_player_id();
my_log.p_game_id = game_id;
my_log.p_table_id = _table_id;
log.Error(my_log.ToString());
}
}
#endregion
#region f_update_hedgeem_control_board_cards_with_info_from_server
/// <summary>
/// This method is used to get the values of all Flop Cards when
/// someone click on Deal Buttons except Hole Button. Then save
/// that value of Flop Card to Session.
/// Also get CSS value from session as described below. */
/// </summary>
private void f_update_hedgeem_control_board_cards_with_info_from_server()
{
try
{
log.Debug("f_update_hedgeem_control_board_cards_with_info_from_server called");
// Create the FLOP card instances
cc_flop_card1 = new hedgeem_control_card();
cc_flop_card2 = new hedgeem_control_card();
cc_flop_card3 = new hedgeem_control_card();
// Get reference to the Application scoped Hedge'Em control that models the 'Turn' card
// xxx NOTE the only reason the TURN card is coded diffently from other board cards was to prove that
// it could be coded as an application scoped control. I (Simon) do not know which method is best.
// Logically there should only ever be one instance of a TURN card at any given table so I was thinking
// it would be best to instantiate only once.
hedgeem_control_card my_turn_card = new hedgeem_control_card();
hedgeem_control_card my_river_card = new hedgeem_control_card();
hedgeem_control_jackpot my_control_jackpot = new hedgeem_control_jackpot();
my_control_jackpot.p_jackpot_balance = my_jackpot_fund;
// Note expect card as short string to be something like ac (ace of clubs), 6d (six of diamonds etc)
// If ZZ us returned this implies the card is to be shown face down.
p_flop_card1_as_short_string = _global_game_state_object.p_flop_card1_string;
p_flop_card2_as_short_string = _global_game_state_object.p_flop_card2_string;
p_flop_card3_as_short_string = _global_game_state_object.p_flop_card3_string;
p_turn_as_short_string = _global_game_state_object.p_turn_card_string;
p_river_as_short_string = _global_game_state_object.p_river_card_string;
// Set the FLOP, TURN and RIVER card values using values specified by server
// E.g. if the Server thinks the FLOP card in 'Six of clubs' (6c) set GUI control to 6c
cc_flop_card1.p_card_as_short_string = p_flop_card1_as_short_string;
cc_flop_card2.p_card_as_short_string = p_flop_card2_as_short_string;
cc_flop_card3.p_card_as_short_string = p_flop_card3_as_short_string;
my_turn_card.p_card_as_short_string = p_turn_as_short_string;
my_river_card.p_card_as_short_string = p_river_as_short_string;
// Set the style attribute for the Board card (e.g. whether they are position in left,right or middle position)
cc_flop_card1.p_enum_card_position = enum_card_position.MIDDLE;
cc_flop_card2.p_enum_card_position = enum_card_position.MIDDLE;