//Load messages from data into EmailInboxes void InitializeMessages() { //Inbox XmlSerializer serialize = new XmlSerializer(typeof(EmailInbox)); FileStream file = new FileStream(Application.streamingAssetsPath + "/Data/inbox.xml", FileMode.Open); inboxData = (EmailInbox)serialize.Deserialize(file); //Sent file = new FileStream(Application.streamingAssetsPath + "/Data/sent.xml", FileMode.Open); //If there is new sent data, then use that instead if (File.Exists(Application.streamingAssetsPath + "/Data/newsent.xml")) { file = new FileStream(Application.streamingAssetsPath + "/Data/newsent.xml", FileMode.Open); } sentData = (EmailInbox)serialize.Deserialize(file); //Spam file = new FileStream(Application.streamingAssetsPath + "/Data/spam.xml", FileMode.Open); spamData = (EmailInbox)serialize.Deserialize(file); //Trash file = new FileStream(Application.streamingAssetsPath + "/Data/trash.xml", FileMode.Open); trashData = (EmailInbox)serialize.Deserialize(file); //More sanity checking if (gameController != null) { if (gameController.GetComponent <GameController>().PhishingResponse&& gameController.GetComponent <GameController>().PhishingPuzzle) { //Load phishing response XmlSerializer ser = new XmlSerializer(typeof(EmailInbox.Message)); file = new FileStream(Application.streamingAssetsPath + "/Data/phishingresponse.xml", FileMode.Open); EmailInbox.Message phishingResponse = (EmailInbox.Message)ser.Deserialize(file); //Get time for the response phishingResponse.time = GetTime(); //Add to inbox inboxData.messageList.Insert(0, phishingResponse); } } //Default to inbox InstantiateMessages(inboxData); }
//Event handler for send public void OnClickSend() { //Sequentially check if any conditions failed bool conditionsPassed = true; //Check to field, must be exact string to = toField.text; if (to != toTarget) { conditionsPassed = false; } //Check subject, need to have a certain number of keywords string subject = subjectField.text; int subjectMatchCount = 0; foreach (string targetWord in subjectTargets) { //Ignore case if (subject.IndexOf(targetWord, 0, StringComparison.CurrentCultureIgnoreCase) != -1) { subjectMatchCount++; } } //Failed if (subjectMatchCount < subjectMatchCountTarget) { conditionsPassed = false; } //Check message, need to have a certain number of keywords string message = messageField.text; int messageMatchCount = 0; foreach (string targetWord in messageTargets) { //Ignore case if (message.IndexOf(targetWord, 0, StringComparison.CurrentCultureIgnoreCase) != -1) { messageMatchCount++; } } //Failed if (messageMatchCount < messageMatchCountTarget) { conditionsPassed = false; } //Good email if (conditionsPassed) { if (gameController != null) { gameController.GetComponent <GameController>().PhishingPuzzle = true; } } //Adding sent email to sent list EmailInbox.Message newSent = new EmailInbox.Message(to, subject, GetTime(), message); sentData.messageList.Insert(0, newSent); //Serialize XmlSerializer serializer = new XmlSerializer(typeof(EmailInbox)); TextWriter writer = new StreamWriter(Application.streamingAssetsPath + "/Data/newsent.xml"); serializer.Serialize(writer, sentData); //Close and clear email compose window toField.text = ""; subjectField.text = ""; messageField.text = ""; OnClickComposeClose(); }