private void RegisterOnMasterServer(ushort port, int maxPlayers, string masterServerHost, ushort masterServerPort, JSONNode masterServerData) { // The Master Server communicates over TCP TCPMasterClient client = new TCPMasterClient(); // Once this client has been accepted by the master server it should send it's get request client.serverAccepted += () => { try { Frame.Text temp = Frame.Text.CreateFromString(client.Time.Timestep, masterServerData.ToString(), true, Receivers.Server, MessageGroupIds.MASTER_SERVER_REGISTER, true); //Debug.Log(temp.GetData().Length); // Send the request to the server client.Send(temp); } catch { // If anything fails, then this client needs to be disconnected client.Disconnect(true); client = null; } }; client.Connect(masterServerHost, masterServerPort); Networker.disconnected += () => { client.Disconnect(false); MasterServerNetworker = null; }; MasterServerNetworker = client; }
/// <summary> /// Positions a string within a frame according to the positioning instructions /// stored in the provided text anchor. /// </summary> /// <param name="anchor">Text anchor the string will be positioned for</param> /// <param name="bounds">Boundaries of the control the string is rendered in</param> /// <param name="text">String that will be positioned</param> /// <returns>The position of the string within the control</returns> private Vector2 positionText(ref Frame.Text anchor, ref RectangleF bounds, string text) { Vector2 textSize = anchor.Font.MeasureString(text); float x, y; switch (anchor.HorizontalPlacement) { case Frame.HorizontalTextAlignment.Left: { x = bounds.Left; break; } case Frame.HorizontalTextAlignment.Right: { x = bounds.Right - textSize.X; break; } case Frame.HorizontalTextAlignment.Center: default: { x = (bounds.Width - textSize.X) / 2.0f + bounds.Left; break; } } switch (anchor.VerticalPlacement) { case Frame.VerticalTextAlignment.Top: { y = bounds.Top; break; } case Frame.VerticalTextAlignment.Bottom: { y = bounds.Bottom - anchor.Font.LineSpacing; break; } case Frame.VerticalTextAlignment.Center: default: { y = (bounds.Height - anchor.Font.CharHeight) / 2.0f + bounds.Top; break; } } return(new Vector2(floor(x + anchor.Offset.X), floor(y + anchor.Offset.Y))); }
private void RegisterOnMasterServer(ushort port, int maxPlayers, string masterServerHost, ushort masterServerPort, bool useElo = false, int eloRequired = 0) { // The Master Server communicates over TCP TCPMasterClient client = new TCPMasterClient(); // Once this client has been accepted by the master server it should send it's get request client.serverAccepted += () => { try { // Create the get request with the desired filters JSONNode sendData = JSONNode.Parse("{}"); JSONClass registerData = new JSONClass(); registerData.Add("id", "myGame"); registerData.Add("name", "Forge Game"); registerData.Add("port", new JSONData(port)); registerData.Add("playerCount", new JSONData(0)); registerData.Add("maxPlayers", new JSONData(maxPlayers)); registerData.Add("comment", "Demo comment..."); registerData.Add("type", "Deathmatch"); registerData.Add("mode", "Teams"); registerData.Add("protocol", "udp"); registerData.Add("elo", new JSONData(eloRequired)); registerData.Add("useElo", new JSONData(useElo)); sendData.Add("register", registerData); Frame.Text temp = Frame.Text.CreateFromString(client.Time.Timestep, sendData.ToString(), true, Receivers.Server, MessageGroupIds.MASTER_SERVER_REGISTER, true); //Debug.Log(temp.GetData().Length); // Send the request to the server client.Send(temp); } catch { // If anything fails, then this client needs to be disconnected client.Disconnect(true); client = null; } }; client.Connect(masterServerHost, masterServerPort); Networker.disconnected += () => { client.Disconnect(false); MasterServerNetworker = null; }; MasterServerNetworker = client; }
/// <summary> /// Builds a text list from the text placements specified in the provided node /// </summary> /// <param name="frameElement"> /// XML node for the frame whose text placements wille be processed /// </param> /// <param name="fonts"> /// Font lookup table used to associate a text's font id to the real font /// </param> /// <returns> /// A list of the texts that have been extracted from the frame XML node /// </returns> public static Frame.Text[] Build( XElement frameElement, IDictionary <string, SpriteFont> fonts ) { var texts = new List <Frame.Text>(); foreach (XElement element in frameElement.Descendants("text")) { string font = element.Attribute("font").Value; string horizontalPlacement = element.Attribute("hplacement").Value; string verticalPlacement = element.Attribute("vplacement").Value; XAttribute xOffsetAttribute = element.Attribute("xoffset"); int xOffset = (xOffsetAttribute == null) ? 0 : int.Parse(xOffsetAttribute.Value); XAttribute yOffsetAttribute = element.Attribute("yoffset"); int yOffset = (yOffsetAttribute == null) ? 0 : int.Parse(yOffsetAttribute.Value); XAttribute colorAttribute = element.Attribute("color"); Color color; if (colorAttribute == null) { color = Color.White; } else { color = colorFromString(colorAttribute.Value); } var text = new Frame.Text() { Font = fonts[font], HorizontalPlacement = horizontalPlacementFromString( horizontalPlacement ), VerticalPlacement = verticalPlacementFromString( verticalPlacement ), Offset = new Point(xOffset, yOffset), Color = color }; texts.Add(text); } return(texts.ToArray()); }
/// <summary> /// Builds a text list from the text placements specified in the provided node /// </summary> /// <param name="frameNode"> /// XML node for the frame whose text placements wille be processed /// </param> /// <param name="fonts"> /// Font lookup table used to associate a text's font id to the real font /// </param> /// <returns> /// A list of the texts that have been extracted from the frame XML node /// </returns> public static Frame.Text[] Build( XmlNode frameNode, IDictionary <string, SpriteFont> fonts ) { XmlNodeList textNodes = frameNode.SelectNodes("text"); Frame.Text[] texts = new Frame.Text[textNodes.Count]; for (int index = 0; index < textNodes.Count; ++index) { string font = textNodes[index].Attributes["font"].Value; string horizontalPlacement = textNodes[index].Attributes["hplacement"].Value; string verticalPlacement = textNodes[index].Attributes["vplacement"].Value; XmlAttribute xOffsetAttribute = textNodes[index].Attributes["xoffset"]; int xOffset = (xOffsetAttribute == null) ? 0 : int.Parse(xOffsetAttribute.Value); XmlAttribute yOffsetAttribute = textNodes[index].Attributes["yoffset"]; int yOffset = (yOffsetAttribute == null) ? 0 : int.Parse(yOffsetAttribute.Value); XmlAttribute colorAttribute = textNodes[index].Attributes["color"]; Color color; if (colorAttribute == null) { color = Color.White; } else { color = colorFromString(colorAttribute.Value); } texts[index].Font = fonts[font]; texts[index].HorizontalPlacement = horizontalPlacementFromString( horizontalPlacement ); texts[index].VerticalPlacement = verticalPlacementFromString( verticalPlacement ); texts[index].Offset = new Point(xOffset, yOffset); texts[index].Color = color; } return(texts); }
/// <summary> /// Builds a text list from the text placements specified in the provided node /// </summary> /// <param name="frameElement"> /// XML node for the frame whose text placements wille be processed /// </param> /// <param name="fonts"> /// Font lookup table used to associate a text's font id to the real font /// </param> /// <returns> /// A list of the texts that have been extracted from the frame XML node /// </returns> public static Frame.Text[] Build( XElement frameElement, IDictionary<string, SpriteFont> fonts ) { var texts = new List<Frame.Text>(); foreach(XElement element in frameElement.Descendants("text")) { string font = element.Attribute("font").Value; string horizontalPlacement = element.Attribute("hplacement").Value; string verticalPlacement = element.Attribute("vplacement").Value; XAttribute xOffsetAttribute = element.Attribute("xoffset"); int xOffset = (xOffsetAttribute == null) ? 0 : int.Parse(xOffsetAttribute.Value); XAttribute yOffsetAttribute = element.Attribute("yoffset"); int yOffset = (yOffsetAttribute == null) ? 0 : int.Parse(yOffsetAttribute.Value); XAttribute colorAttribute = element.Attribute("color"); Color color; if (colorAttribute == null) { color = Color.White; } else { color = colorFromString(colorAttribute.Value); } var text = new Frame.Text() { Font = fonts[font], HorizontalPlacement = horizontalPlacementFromString( horizontalPlacement ), VerticalPlacement = verticalPlacementFromString( verticalPlacement ), Offset = new Point(xOffset, yOffset), Color = color }; texts.Add(text); } return texts.ToArray(); }
/// <summary> /// Builds a text list from the text placements specified in the provided node /// </summary> /// <param name="frameNode"> /// XML node for the frame whose text placements wille be processed /// </param> /// <param name="fonts"> /// Font lookup table used to associate a text's font id to the real font /// </param> /// <returns> /// A list of the texts that have been extracted from the frame XML node /// </returns> public static Frame.Text[] Build( XmlNode frameNode, IDictionary<string, SpriteFont> fonts ) { XmlNodeList textNodes = frameNode.SelectNodes("text"); Frame.Text[] texts = new Frame.Text[textNodes.Count]; for (int index = 0; index < textNodes.Count; ++index) { string font = textNodes[index].Attributes["font"].Value; string horizontalPlacement = textNodes[index].Attributes["hplacement"].Value; string verticalPlacement = textNodes[index].Attributes["vplacement"].Value; XmlAttribute xOffsetAttribute = textNodes[index].Attributes["xoffset"]; int xOffset = (xOffsetAttribute == null) ? 0 : int.Parse(xOffsetAttribute.Value); XmlAttribute yOffsetAttribute = textNodes[index].Attributes["yoffset"]; int yOffset = (yOffsetAttribute == null) ? 0 : int.Parse(yOffsetAttribute.Value); XmlAttribute colorAttribute = textNodes[index].Attributes["color"]; Color color; if (colorAttribute == null) { color = Color.White; } else { color = colorFromString(colorAttribute.Value); } texts[index].Font = fonts[font]; texts[index].HorizontalPlacement = horizontalPlacementFromString( horizontalPlacement ); texts[index].VerticalPlacement = verticalPlacementFromString( verticalPlacement ); texts[index].Offset = new Point(xOffset, yOffset); texts[index].Color = color; } return texts; }