internal void addEvent(HOHEvent oneEvent) { if (oneEvent.team != null) { if (oneEvent.eventType == HOHEvent.HOHEventType.SolutionEventType) { try { pointsForTeam.Clear(); } catch {} try { puzzlesTakenForTeam.Remove(oneEvent.team); } catch {} try { pointsForTeamAtPuzzle.Clear(); } catch {} try { placeForTeamAtPuzzle.Clear(); } catch { } try { correctPlaceForTeamAtPuzzle.Clear(); } catch { } placeForTeam.Clear(); } if (oneEvent.eventType == HOHEvent.HOHEventType.HintReplyEventType) { int hintTakenCount = getHintsTakenForTeam(oneEvent.team); this.hintsTakenForTeam[oneEvent.team] = hintTakenCount + 1; int hintTakenCountAtPuzzle = getHintsTakenForTeamAtPuzzle(oneEvent.team, oneEvent.puzzle); try { hintsTakenForTeamAtPuzzle[oneEvent.team][oneEvent.puzzle] = hintTakenCountAtPuzzle + 1; } catch {} try { pointsForTeam.Remove(oneEvent.team); } catch {} try { pointsForTeamAtPuzzle[oneEvent.team].Remove(oneEvent.puzzle); } catch {} placeForTeam.Clear(); } if (oneEvent.eventType == HOHEvent.HOHEventType.StandingsReplyEventType) { int standingsTakenCount = getStandingsTakenForTeam(oneEvent.team); this.standingsTakenForTeam[oneEvent.team] = standingsTakenCount + 1; } if (oneEvent.eventType == HOHEvent.HOHEventType.GivingUpEventType) { try { pointsForTeam.Remove(oneEvent.team); } catch {} placeForTeam.Clear(); } } this.events.Add(oneEvent); if (oneEvent.team != null) { oneEvent.team.events.Add(oneEvent); } if (oneEvent.puzzle != null) { oneEvent.puzzle.events.Add(oneEvent); } }
internal List<HOHEvent> parseSMS(SMSMessageProcess smsMessageProces) { HOHTeam team = null; HOHPuzzle puzzle = null; string teamName = "", puzzleName = "", remaining = ""; List<HOHEvent> newEvents = new List<HOHEvent>(); string smsBody = smsMessageProces.getMessageBody(); smsBody = " " + smsBody.Trim().ToUpper(); teamName = smsBody; do { teamName = teamName.Substring(0, teamName.LastIndexOf(" ")); remaining = smsBody.Substring(teamName.Length); team = this.smsManager.dataManager.gameModel.getTeamForTeamId(teamName.Trim().ToUpper()); } while (team == null && teamName.CompareTo("") != 0); if (team == null) return null; if (remaining.EndsWith("NAPOVEDA")) { puzzleName = remaining.Substring(0, remaining.Length - "NAPOVEDA".Length).Trim(); puzzle = this.smsManager.dataManager.gameModel.getPuzzleForPuzzleId(puzzleName.Trim().ToUpper()); if (puzzle == null) return null; HOHEvent newEvent = new HOHEvent(); newEvent.eventType = HOHEvent.HOHEventType.HintRequestEventType; newEvent.SMSText = smsBody; newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber(); newEvent.dateTime = smsMessageProces.getReceivedDate(); newEvent.team = team; newEvent.puzzle = puzzle; newEvents.Add(newEvent); } else if (remaining.EndsWith("PORADI")) { HOHEvent newEvent = new HOHEvent(); newEvent.eventType = HOHEvent.HOHEventType.StandigsRequestType; newEvent.SMSText = smsBody; newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber(); newEvent.dateTime = smsMessageProces.getReceivedDate(); newEvent.team = team; newEvent.puzzle = null; newEvents.Add(newEvent); } else if (remaining.EndsWith("VZDAVAME")) { HOHEvent newEvent = new HOHEvent(); newEvent.eventType = HOHEvent.HOHEventType.GivingUpEventType; newEvent.SMSText = smsBody; newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber(); newEvent.dateTime = smsMessageProces.getReceivedDate(); newEvent.team = team; newEvent.puzzle = null; newEvents.Add(newEvent); } else { String answer = ""; if (remaining.LastIndexOf(puzzleIdVsSolutionSeparator) != -1) do { int lastdelim = remaining.LastIndexOf(puzzleIdVsSolutionSeparator); puzzle = null; puzzleName = remaining.Substring(0, lastdelim); answer = remaining.Substring(lastdelim + 1); do { puzzleName = puzzleName.Substring(puzzleName.IndexOf(" ") + 1); puzzle = this.smsManager.dataManager.gameModel.getPuzzleForPuzzleId(puzzleName.Trim().ToUpper()); } while (puzzle == null && puzzleName.IndexOf(" ") > -1); remaining = remaining.Substring(0, lastdelim - puzzleName.Length); if (puzzle != null) { HOHEvent newEvent = new HOHEvent(); newEvent.eventType = HOHEvent.HOHEventType.SolutionEventType; newEvent.SMSText = smsBody; newEvent.phoneNumber = smsMessageProces.getRecipientPhoneNumber(); newEvent.dateTime = smsMessageProces.getReceivedDate(); newEvent.team = team; newEvent.puzzle = puzzle; newEvent.solutionText = answer.Trim().ToUpper(); newEvents.Add(newEvent); } } while (remaining.LastIndexOf(puzzleIdVsSolutionSeparator) != -1 && puzzle != null); if (remaining.Trim().CompareTo("") != 0 || puzzle == null) return null; } return newEvents; }
private bool sendSms(SmsMessage msg, HOHEvent newEvent) { try { if (msg.To.Count == 0 || msg.To[0] == null || msg.To[0].Address.CompareTo("<>") == 0) throw new Exception(); msg.Send(); } catch { return false; } return true; }
internal void sendSmsStandingsForTeamAndPuzzle(HOHTeam team, HOHPuzzle puzzle, string phoneNumber, bool live) { if (puzzle == null || team == null) return; int place = this.dataManager.gameModel.getPlaceForTeamAtPuzzle(team, puzzle); string smsText = String.Format("Vase poradi na sifre {0}: {1}.", puzzle.name, place); /* TODO if (place > 0) smsText += String.Format(" Pred vami: {0}", dataManager.gameModel.); if (place > 1) smsText += String.Format(" Prvni na sifre: {0}", dataManager.gameModel.); */ HOHEvent newEvent = new HOHEvent(HOHEvent.HOHEventType.StandingsReplyEventType); newEvent.team = team; newEvent.puzzle = puzzle; newEvent.phoneNumber = phoneNumber; newEvent.SMSText = smsText; SmsMessage msg = new SmsMessage(); msg.Body = smsText; msg.To.Add(new Recipient(phoneNumber)); if (live && !sendSms(msg, newEvent)) { newEvent.eventType = HOHEvent.HOHEventType.SendFailedEventType; } dataManager.addEvents(new List<HOHEvent>(new HOHEvent[] { newEvent }), live); }
internal void sendSmsStandingsForTeam(HOHTeam team, string phoneNumber, bool live) { if (team == null) return; int place = dataManager.gameModel.getTeamPlacesList().IndexOf(team); string smsText = String.Format("Vase poradi ve hre: {0}. ({1} b)", place + 1, dataManager.gameModel.getPointsForTeam(team)); if (place > 0) { smsText += String.Format(" Pred vami: {0} ({1} b)", dataManager.gameModel.getTeamPlacesList()[place - 1].name, dataManager.gameModel.getPointsForTeam(dataManager.gameModel.getTeamPlacesList()[place - 1])); } if (place < dataManager.gameModel.getTeamPlacesList().Count() - 1) { smsText += String.Format(" Za vami: {0} ({1} b)", dataManager.gameModel.getTeamPlacesList()[place + 1].name, dataManager.gameModel.getPointsForTeam(dataManager.gameModel.getTeamPlacesList()[place + 1])); } if (place > 0) { smsText += String.Format(" Prvni misto: {0} ({1} b)", dataManager.gameModel.getTeamPlacesList()[0].name, dataManager.gameModel.getPointsForTeam(dataManager.gameModel.getTeamPlacesList()[0])); } HOHEvent newEvent = new HOHEvent(HOHEvent.HOHEventType.StandingsReplyEventType); newEvent.team = team; newEvent.phoneNumber = phoneNumber; newEvent.SMSText = smsText; SmsMessage msg = new SmsMessage(); msg.Body = smsText; msg.To.Add(new Recipient(phoneNumber)); if (live && !sendSms(msg, newEvent)) { newEvent.eventType = HOHEvent.HOHEventType.SendFailedEventType; } dataManager.addEvents(new List<HOHEvent>(new HOHEvent[] { newEvent }), live); }
internal void sendSmsHintForTeamAndPuzzle(HOHTeam team, HOHPuzzle puzzle, string phoneNumber, bool live) { if (puzzle == null) return; if (puzzle.hint.Equals("")) return; string smsText = String.Format("Napoveda pro {0}: {1}", puzzle.name, puzzle.hint); HOHEvent newEvent = new HOHEvent(HOHEvent.HOHEventType.HintReplyEventType); newEvent.team = team; newEvent.puzzle = puzzle; newEvent.phoneNumber = phoneNumber; newEvent.SMSText = smsText; SmsMessage msg = new SmsMessage(); msg.Body = smsText; msg.To.Add(new Recipient(phoneNumber)); if (live && !sendSms(msg, newEvent)) { newEvent.eventType = HOHEvent.HOHEventType.SendFailedEventType; } dataManager.addEvents(new List<HOHEvent>(new HOHEvent[] { newEvent }), live); }