internal static void ModelessMessageBox(tvProfile aoProfile, string asNamespace, string asTitle, string asMessage) { String lcsMsgBoxExeName = "MessageBox.exe"; System.Diagnostics.Process[] loProcessArray = System.Diagnostics.Process.GetProcessesByName( System.IO.Path.GetFileNameWithoutExtension(lcsMsgBoxExeName)); if (loProcessArray.Length < aoProfile.iValue("-ModelessMessageBoxMaxCount", 3)) { string lsMsgExePathFile = Path.Combine( Path.GetDirectoryName(aoProfile.sExePathFile), lcsMsgBoxExeName); tvFetchResource.ToDisk(asNamespace, lcsMsgBoxExeName, lsMsgExePathFile); if (File.Exists(lsMsgExePathFile)) { System.Diagnostics.Process.Start(lsMsgExePathFile, String.Format( "-Title=\"{0}: {1}\" -Message=\"{2}\"" , asNamespace.Replace("\"", "'") , asTitle.Replace("\"", "'") , asMessage.Replace("\"", "'") )); } } }
public static string sMachineKeyPathFile(tvProfile aoProfile, X509Certificate2 aoCertificate) { string lsMachineKeyPathFile = null; try { lsMachineKeyPathFile = Path.Combine(aoProfile.sValue("-MachineKeysPath", @"C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys") , HashClass.GetKeyFileName(aoCertificate)); } catch (InvalidOperationException ex) { if (aoProfile.bValue("-DeclareErrorOnPrivateKeyFileCleanedUp", false)) { Type ltDoGetCert = Type.GetType("DoGetCert"); if (null == ltDoGetCert) { throw ex; } else { ltDoGetCert.GetMethod("LogIt").Invoke(null, new object[] { String.Format("GetCertServiceFault: {0}{1}{2}{3}" , ex.Message, (null == ex.InnerException ? "": "; " + ex.InnerException.Message) , Environment.NewLine , ex.StackTrace) }); } } } return(lsMachineKeyPathFile); }
public static tvMessageBoxResults Show( Window aoWindow , string asMessageText , string asMessageCaption , tvMessageBoxButtons aeTvMessageBoxButtons , tvMessageBoxIcons aeTvMessageBoxIcon , tvMessageBoxCheckBoxTypes aeTvMessageBoxCheckBoxType , tvProfile aoProfile , string asProfilePromptKey , tvMessageBoxResults aeTvMessageBoxResultsOverride ) { return(tvMessageBox.Show( aoWindow , asMessageText , asMessageCaption , aeTvMessageBoxButtons , aeTvMessageBoxIcon , false , aeTvMessageBoxCheckBoxType , aoProfile , asProfilePromptKey , aeTvMessageBoxResultsOverride )); }
public Deck(tvProfile profile) { Profile = profile; this.CardList = GenerateDeck(); // Randomize the cards in the deck Shuffle(this.CardList); }
public static string sHashPw(tvProfile aoProfile) { StringBuilder lsbHashPw = new StringBuilder(); byte[] lbtArray = new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(aoProfile.ToString())); foreach (byte lbtValue in lbtArray) { lsbHashPw.Append(lbtValue.ToString()); } return(lsbHashPw.ToString()); }
public static void ShowModelessError( Window aoWindow , string asMessageText , string asMessageCaption , tvProfile aoProfile ) { tvMessageBox.Show( aoWindow , asMessageText , asMessageCaption , tvMessageBoxButtons.OK , tvMessageBoxIcons.Error , true ); }
// Scan data from the profile file to generate the cards for the deck. // ROBIN TODO: Generalize this method so that it works for cards with any properties (not just those specific to Monopoly Deal). public List <Card> GenerateDeck() { // Variables to hold temporary data. string name; CardType cardType; EnhancementType enhanceType; int value; PropertyType propertyType; PropertyType altPropertyType; string uriPath; string soundUriPath; int actionID; List <Card> cardList = new List <Card>(); // Each card must have a unique ID. int cardID = 0; foreach (DictionaryEntry keyVal in Profile) { string resourceName = keyVal.Key as string; tvProfile cardProfile = Profile.oProfile(resourceName); for (int a = 0; a < cardProfile.iValue("-Count", 0); ++a) { name = cardProfile.sValue("-Name", ""); cardType = (CardType)Enum.Parse(typeof(CardType), cardProfile.sValue("-CardType", "")); enhanceType = (EnhancementType)Enum.Parse(typeof(EnhancementType), cardProfile.sValue("-EnhancementType", "None")); value = cardProfile.iValue("-Value", 0); propertyType = (cardProfile.sValue("-PropertyType", "") == "") ? PropertyType.None : (PropertyType)Enum.Parse(typeof(PropertyType), cardProfile.sValue("-PropertyType", "")); altPropertyType = (cardProfile.sValue("-AltPropertyType", "") == "") ? PropertyType.None : (PropertyType)Enum.Parse(typeof(PropertyType), cardProfile.sValue("-AltPropertyType", "")); uriPath = resourceName.Replace("-", string.Empty) + "DrawingImage"; string soundEffectFileName = cardProfile.sValue("-SoundEffectFile", string.Empty); soundUriPath = string.IsNullOrWhiteSpace(soundEffectFileName) ? ResourceList.UriPathEmpty : ResourceList.UriPathAudioFolder + soundEffectFileName; actionID = (cardProfile.sValue("-ActionID", "") == "") ? -1 : Convert.ToInt32((cardProfile.sValue("-ActionID", ""))); cardList.Add(new Card(name, cardType, value, propertyType, altPropertyType, uriPath, soundUriPath, actionID, cardID)); // Iterate the card ID so that it is different for the next card. cardID++; } } return(cardList); }
public LaunchScreen() { InitializeComponent(); this.Title = "Monopoly Deal Setup"; // Load cached settings from Profile. settings = ClientUtilities.GetClientSettings(ResourceList.SettingsFilePath); // Populate fields with settings. this.PlayerNameTextBox.Text = settings.sValue(ResourceList.SettingNameKey, string.Empty); this.IPAddressTextBox.Text = settings.sValue(ResourceList.SettingIpAddressKey, string.Empty); this.PortTextBox.Text = settings.sValue(ResourceList.SettingPortKey, ResourceList.SettingPortDefaultValue); // Play the sound of silence to allow the game client to adjust the volume of the application. // Without this, the volume would not be able to be adjusted until after the first sound is played. ClientUtilities.PlaySound(ResourceList.UriPathSilence); }
public static string sMachineKeyPathFile(tvProfile aoProfile, X509Certificate2 aoCertificate) { string lsMachineKeyPathFile = null; try { lsMachineKeyPathFile = Path.Combine(aoProfile.sValue("-MachineKeysPath", @"C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys") , HashClass.GetKeyFileName(aoCertificate)); } catch (InvalidOperationException ex) { if (aoProfile.bValue("-DeclareErrorOnPrivateKeyFileCleanedUp", false)) { DoGetCert.LogIt(aoProfile, DoGetCert.sExceptionMessage(ex)); } } return(lsMachineKeyPathFile); }
public static void ResetAllPrompts( Window aoWindow , string asMessageText , string asMessageCaption , tvProfile aoProfile ) { if (tvMessageBoxResults.Yes == tvMessageBox.Show( aoWindow , asMessageText , asMessageCaption , tvMessageBoxButtons.YesNo , tvMessageBoxIcons.Alert ) ) { aoProfile.Remove(msProfilePromptKeyPrefix + "*"); aoProfile.Save(); } }
public static void ShowModelessError( Window aoWindow , string asMessageText , string asMessageCaption , tvProfile aoProfile , string asProfilePromptKey ) { tvMessageBox.Show( aoWindow , asMessageText , asMessageCaption , tvMessageBoxButtons.OK , tvMessageBoxIcons.Error , true , tvMessageBoxCheckBoxTypes.SkipThis , aoProfile , asProfilePromptKey , tvMessageBoxResults.None ); }
public static tvMessageBoxResults ShowModeless( Window aoWindow , string asMessageText , string asMessageCaption , tvMessageBoxButtons aeTvMessageBoxButtons , tvMessageBoxIcons aeTvMessageBoxIcon , tvMessageBoxCheckBoxTypes aeTvMessageBoxCheckBoxType , tvProfile aoProfile , string asProfilePromptKey ) { return(tvMessageBox.Show( aoWindow , asMessageText , asMessageCaption , aeTvMessageBoxButtons , aeTvMessageBoxIcon , true , aeTvMessageBoxCheckBoxType , aoProfile , asProfilePromptKey , tvMessageBoxResults.None )); }
public static string sMachineKeyPathFile(tvProfile aoProfile, X509Certificate2 aoCertificate) { return(Path.Combine(aoProfile.sValue("-MachineKeysPath", @"C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys") , HashClass.GetKeyFileName(aoCertificate))); }
public static tvMessageBoxResults Show( Window aoWindow , string asMessageText , string asMessageCaption , tvMessageBoxButtons aeTvMessageBoxButtons , tvMessageBoxIcons aeTvMessageBoxIcon , bool abShowModeless , tvMessageBoxCheckBoxTypes aeTvMessageBoxCheckBoxType , tvProfile aoProfile , string asProfilePromptKey , tvMessageBoxResults aeTvMessageBoxResultsOverride ) { tvMessageBoxResults liTvMessageBoxResult = tvMessageBoxResults.None; string lsPromptAnswerKey = null; bool lbUseCheckBox = tvMessageBoxCheckBoxTypes.None != aeTvMessageBoxCheckBoxType; if (lbUseCheckBox) { // Insert the prompt key prefix if it's not already there. A common prefix // is necessary to allow for the removal of all prompt keys as needed. if (!asProfilePromptKey.StartsWith(msProfilePromptKeyPrefix)) { // Strip leading hyphen. if (asProfilePromptKey.StartsWith("-")) { asProfilePromptKey = asProfilePromptKey.Substring(1, asProfilePromptKey.Length - 1); } // Insert prefix. asProfilePromptKey = msProfilePromptKeyPrefix + asProfilePromptKey; } // Make the answer key from the prompt key and the prompt key suffix. lsPromptAnswerKey = asProfilePromptKey + msProfilePromptKeySuffix; // Only the first display of a modeless dialog can contain a checkbox. // Why? Because the first prompt is not modeless. That's the only way // to capture the checkbox value. BTW, "lbUseCheckBox" is reset here // for use outside of this block to avoid the default setting next. if (abShowModeless) { lbUseCheckBox = !aoProfile.ContainsKey(asProfilePromptKey); } if (!aoProfile.bValue(asProfilePromptKey, false) && aoProfile.ContainsKey(lsPromptAnswerKey)) { // Do not prompt. Return the previous stored answer instead. return((tvMessageBoxResults)aoProfile.iValue( lsPromptAnswerKey, (int)tvMessageBoxResults.None)); } } if (null == asMessageCaption) { // No caption provided. Let's try to get one another way. if (null != aoWindow) // Try window title first. { asMessageCaption = aoWindow.Title; } else if (null != Application.Current && null != Application.Current.MainWindow) // Next try for application name. { asMessageCaption = Application.Current.MainWindow.Name; } else { asMessageCaption = System.IO.Path.GetFileNameWithoutExtension(Application.ResourceAssembly.Location); } } if (null != aoWindow) { aoWindow.Cursor = null; // Turn off wait cursor in parent window. } tvMessageBox loMsgBox = new tvMessageBox(); loMsgBox.MessageText.Text = asMessageText; // Use some parent window attributes, if available. if (null != aoWindow) { // Use the parent window's icon. loMsgBox.Icon = aoWindow.Icon; // Use the given asMessageCaption as the MsgBox title, if not null. // Otherwise use the parent window title with an added question mark. loMsgBox.Title = null != asMessageCaption ? asMessageCaption : aoWindow.Title + "?"; } // Display the MsgBox header / title (ie. the caption), if provided. if (null != asMessageCaption) { loMsgBox.MessageTitle.Content = asMessageCaption; loMsgBox.MessageTitle.Visibility = Visibility.Visible; } loMsgBox.SelectButtons(aeTvMessageBoxButtons); loMsgBox.SelectIcon(aeTvMessageBoxIcon); if (lbUseCheckBox) { switch (aeTvMessageBoxCheckBoxType) { case tvMessageBoxCheckBoxTypes.DontAsk: loMsgBox.chkDontAsk.Visibility = Visibility.Visible; break; case tvMessageBoxCheckBoxTypes.SkipThis: loMsgBox.chkSkipThis.Visibility = Visibility.Visible; break; } } if (!abShowModeless) { loMsgBox.ShowDialog(); } else { // It can only be modeless after the checkbox has been stored. if (lbUseCheckBox) { loMsgBox.ShowDialog(); } else { loMsgBox.Show(); } } if (lbUseCheckBox) { bool lbCheckBoxValue = false; switch (aeTvMessageBoxCheckBoxType) { case tvMessageBoxCheckBoxTypes.DontAsk: lbCheckBoxValue = (bool)loMsgBox.chkDontAsk.IsChecked; break; case tvMessageBoxCheckBoxTypes.SkipThis: lbCheckBoxValue = (bool)loMsgBox.chkSkipThis.IsChecked; break; } // Use the answer override whenever not "none". This value is // necessary for certain stored answers that don't make sense // in a given context (eg. both "skip this" and "cancel" selected). if (tvMessageBoxResults.None == aeTvMessageBoxResultsOverride) { aeTvMessageBoxResultsOverride = loMsgBox.eTvMessageBoxResult; } // Reverse the boolean. "Don't ask" or "Skip this" means "Don't prompt". aoProfile[asProfilePromptKey] = !lbCheckBoxValue; aoProfile[lsPromptAnswerKey] = (int)aeTvMessageBoxResultsOverride; aoProfile.Save(); } liTvMessageBoxResult = loMsgBox.eTvMessageBoxResult; return(liTvMessageBoxResult); }
public static string sHashIt(tvProfile aoProfile) { return(HashClass.sHashPw(aoProfile.ToString().Substring(0, 256))); }
public static string sHashIt(tvProfile aoProfile) { return(HashClass.sHashPw(aoProfile)); }
static void Main(string[] args) { // Attempt to load the game configuration from a config file. if (File.Exists(GameObjectsResourceList.FilePathLocalServerSettings)) { Profile = new tvProfile(GameObjectsResourceList.FilePathLocalServerSettings, false); } // If it doesn't exist locally, use the embedded one. else { Profile = ServerUtilities.GetEmbeddedServerSettings(); } // Create a new deck. Deck = new Deck(Profile); // Create a new list of players. PlayerList = new List <Player>(); // Create a new Dicard Pile. DiscardPile = new List <Card>(); // Create new instance of configs. Parameter is "application Id". It has to be same on client and server. Config = new NetPeerConfiguration("game"); // Set server port Config.Port = ServerUtilities.PORT_NUMBER; // Max client amount Config.MaximumConnections = 200; // Enable New messagetype. Explained later Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); // Create new server based on the configs just defined Server = new NetServer(Config); // Start it Server.Start(); // Eh.. Console.WriteLine("Server Started"); // Object that can be used to store and read messages NetIncomingMessage inc; // Check time DateTime time = DateTime.Now; // Create timespan of 30ms TimeSpan timetopass = new TimeSpan(0, 0, 0, 0, 30); // Write to con.. Console.WriteLine("Waiting for new connections"); // Main loop // This kind of loop can't be made in XNA. In there, its basically same, but without while // Or maybe it could be while(new messages) while (true) { // Server.ReadMessage() Returns new messages, that have not yet been read. // If "inc" is null -> ReadMessage returned null -> Its null, so dont do this :) if ((inc = Server.ReadMessage()) != null) { // Theres few different types of messages. To simplify this process, i left only 2 of em here switch (inc.MessageType) { // If incoming message is Request for connection approval // This is the very first packet/message that is sent from client // Here you can do new player initialisation stuff case NetIncomingMessageType.ConnectionApproval: { // Read the first byte of the packet // ( Enums can be casted to bytes, so it be used to make bytes human readable ) if (inc.ReadByte() == (byte)PacketTypes.LOGIN) { Console.WriteLine("Incoming LOGIN"); // Approve clients connection ( Its sort of agreenment. "You can be my client and i will host you" ) inc.SenderConnection.Approve(); // Debug Console.WriteLine("Approved new connection."); } break; } // All messages manually sent from clients are considered "Data" messages. // ( Approval is an automated process ) case NetIncomingMessageType.Data: { Datatype messageType = (Datatype)inc.ReadByte(); // Exclude the sender from the fanout. long idOfSender = inc.SenderConnection.RemoteUniqueIdentifier; switch (messageType) { // Receive an updated Deck from a client. case Datatype.UpdateDeck: { Deck = (Deck)ServerUtilities.ReceiveMessage(inc, messageType); ServerUtilities.SendMessage(Server, Datatype.UpdateDeck, Deck); break; } // Receive an updated DiscardPile from a client. case Datatype.UpdateDiscardPile: { DiscardPile = (List <Card>)ServerUtilities.ReceiveMessage(inc, messageType); ServerUtilities.SendMessage(Server, Datatype.UpdateDiscardPile, DiscardPile); break; } // Add or modify a player in the PlayerList. case Datatype.UpdatePlayer: { Player updatedPlayer = (Player)ServerUtilities.ReceiveMessage(inc, messageType); bool isPlayerInList = false; // If the updated Player is already in the server's list, update that's Player's properties. // Note: This search only works if players have unique names. foreach (Player player in PlayerList) { if (updatedPlayer.Name == player.Name) { player.CardsInHand = updatedPlayer.CardsInHand; player.CardsInPlay = updatedPlayer.CardsInPlay; isPlayerInList = true; break; } } // If the Player is not on the list, add it. if (!isPlayerInList) { PlayerList.Add(updatedPlayer); } // Send the updated PlayerList to all clients. ServerUtilities.SendMessage(Server, Datatype.UpdatePlayerList, PlayerList); break; } // Update the server's Player List and send it to the clients. case Datatype.UpdatePlayerList: { PlayerList = (List <Player>)ServerUtilities.ReceiveMessage(inc, messageType); ServerUtilities.SendMessage(Server, Datatype.UpdatePlayerList, PlayerList); break; } // Send the updated turn to all players. case Datatype.UpdateTurn: { Turn = (Turn)ServerUtilities.ReceiveMessage(inc, messageType); ServerUtilities.SendMessage(Server, Datatype.UpdateTurn, Turn); break; } // Set up the players for the game. This case should be hit only when a client launches the game. case Datatype.LaunchGame: { // Deal the initial hands to the players. for (int i = 0; i < PlayerList.Count; ++i) { PlayerList[i] = new Player(Deck, PlayerList[i].Name); } // Generate the Turn object to keep track of the current turn. Turn = new Turn(PlayerList.Count); // Tell all clients to launch the game and send them the Turn object. ServerUtilities.SendMessage(Server, Datatype.LaunchGame, Turn); break; } case Datatype.TimeToConnect: { string playerToConnect = (String)ServerUtilities.ReceiveMessage(inc, messageType); // Broadcast a message that tells a specific client to launch the game. ServerUtilities.SendMessage(Server, Datatype.TimeToConnect, playerToConnect); break; } case Datatype.RequestRent: { ActionData.RentRequest request = (ActionData.RentRequest)ServerUtilities.ReadRentRequest(inc); ServerUtilities.SendMessage(Server, Datatype.RequestRent, request, idOfClientToExclude: idOfSender); break; } case Datatype.GiveRent: { ActionData.RentResponse response = (ActionData.RentResponse)ServerUtilities.ReadRentResponse(inc); ServerUtilities.SendMessage(Server, Datatype.GiveRent, response); break; } case Datatype.RequestTheft: { ActionData.TheftRequest request = (ActionData.TheftRequest)ServerUtilities.ReadTheftRequest(inc); ServerUtilities.SendMessage(Server, Datatype.RequestTheft, request, idOfClientToExclude: idOfSender); break; } case Datatype.ReplyToTheft: { ActionData.TheftResponse response = (ActionData.TheftResponse)ServerUtilities.ReadTheftResponse(inc); ServerUtilities.SendMessage(Server, Datatype.ReplyToTheft, response, idOfClientToExclude: idOfSender); break; } case Datatype.EndTurn: { Turn = (Turn)ServerUtilities.ReceiveMessage(inc, Datatype.EndTurn); // Send the updated Turn object to the clients. ServerUtilities.SendMessage(Server, Datatype.EndTurn, Turn); break; } // Send the server's Deck to all clients. case Datatype.RequestDeck: { ServerUtilities.SendMessage(Server, Datatype.UpdateDeck, Deck); break; } // Send the server's PlayerList to all clients. case Datatype.RequestPlayerList: { ServerUtilities.SendMessage(Server, Datatype.UpdatePlayerList, PlayerList); break; } case Datatype.PlaySound: { string soundPath = (string)ServerUtilities.ReceiveMessage(inc, messageType); ServerUtilities.SendMessage(Server, Datatype.PlaySound, soundPath); break; } case Datatype.GameEvent: { string serializedEvent = (string)ServerUtilities.ReceiveMessage(inc, messageType); ServerUtilities.SendMessage(Server, Datatype.GameEvent, serializedEvent); break; } } break; } case NetIncomingMessageType.StatusChanged: { // In case status changed // It can be one of these // NetConnectionStatus.Connected; // NetConnectionStatus.Connecting; // NetConnectionStatus.Disconnected; // NetConnectionStatus.Disconnecting; // NetConnectionStatus.None; // NOTE: Disconnecting and Disconnected are not instant unless client is shutdown with disconnect() Console.WriteLine(inc.SenderConnection.ToString() + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status); if (inc.SenderConnection.Status == NetConnectionStatus.Disconnected || inc.SenderConnection.Status == NetConnectionStatus.Disconnecting) { Console.WriteLine("Client was disconnected."); } break; } default: { Console.WriteLine("Message of type: " + inc.MessageType + " received"); break; } } } // If New messages // if 30ms has passed if ((time + timetopass) < DateTime.Now) { time = DateTime.Now; } // While loops run as fast as your computer lets. While(true) can lock your computer up. Even 1ms sleep, lets other programs have piece of your CPU time System.Threading.Thread.Sleep(100); } }