Example #1
0
        protected void changeDescription()
        {
            /*
             * if (Request.Params["newName"] == null)
             *  return;
             * string newName = Request.Params["newName"];
             */

            System.IO.StreamReader reader3 = new System.IO.StreamReader(Request.InputStream);
            string newName = reader3.ReadToEnd();

            newName = Helpers.StripUserHtml(newName);


            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            bc.changeDescription(currentUser.id, newName);

            /*
             * try
             * {
             *  // 2. Open the connection
             *  conn.Open();
             *  // 3. Pass the connection to a command object
             *  //BUG//string query = "exec [dbo].[Movement] @shipId ,@currentUserSession, @direction,@duration,@output";
             *  string query = "[dbo].[ChangeAllianceDescription]";
             *  SqlCommand cmd = new SqlCommand(query, conn);
             *  cmd.CommandType = CommandType.StoredProcedure;
             *
             *
             *  SqlParameter param1 = new SqlParameter();
             *  param1.ParameterName = "@userId";
             *  param1.Value = currentUser.id;
             *  cmd.Parameters.Add(param1);
             *
             *
             *  SqlParameter param3 = new SqlParameter();
             *  param3.ParameterName = "@newDescriptiom";
             *  param3.Value = newName;
             *  cmd.Parameters.Add(param3);
             *
             *  cmd.ExecuteNonQuery();
             *
             *  conn.Close();
             * }
             * finally
             * {
             *  // Close the connection
             *  if (conn != null)
             *  {
             *      conn.Close();
             *  }
             * }
             */

            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #2
0
        public void BCMoveTest()
        {
            string ret = "";

            SpacegameServer.BC.BusinessConnector bc;
            bc = new SpacegameServer.BC.BusinessConnector();

            Ship newShip = Mock.mockShip();

            newShip.systemid   = null;
            newShip.max_hyper  = 10;
            newShip.max_impuls = 10;
            newShip.hyper      = 10;
            newShip.impuls     = 10;

            var        OldPositionX = newShip.field.x;
            List <int> shipIds      = new List <int>();

            shipIds.Add(newShip.id);
            ret = bc.MoveFleet(shipIds, 6, newShip.userid, 1);

            SpacegameServer.BC.XMLGroups.MoveResultTree moveResult = null;
            System.Xml.Serialization.XmlSerializer      serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpacegameServer.BC.XMLGroups.MoveResultTree));
            using (System.IO.TextReader reader = new System.IO.StringReader(ret))
            {
                moveResult = (SpacegameServer.BC.XMLGroups.MoveResultTree)serializer.Deserialize(reader);
            }

            Assert.AreEqual(1, moveResult.result);
            Assert.AreEqual(OldPositionX + 1, moveResult.ships.First(ship => ship.id == newShip.id).posX);
        }
Example #3
0
        protected void getColonyData()
        {
            if (Request.Params["colonyId"] == null)
            {
                return;
            }
            string colonyId = Request.Params["colonyId"];
            int    colonyIdInt;

            if (!Int32.TryParse(colonyId, out colonyIdInt))
            {
                return;
            }

            int userIdInt;

            if (!Int32.TryParse(userId, out userIdInt))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            string xml;

            xml   = bc.getColonySurfacefields(userIdInt, colonyIdInt);
            resp += xml;


            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
        protected void setMessageRead()
        {
            if (Request.Params["messageType"] == null)
            {
                return;
            }
            string messageTypeS = Request.Params["messageType"];

            int messageTypeI;

            if (!Int32.TryParse(messageTypeS, out messageTypeI))
            {
                return;
            }



            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            bc.setAllMessageRead(currentUser.id, messageTypeI);



            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        } // end of getReceivedmessages()
Example #5
0
        protected void Besiege()
        {
            if (Request.Params["shipId"] == null)
            {
                return;
            }
            string shipId = Request.Params["shipId"];
            int    shipIdInt;

            if (!Int32.TryParse(shipId, out shipIdInt))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            bc.Besiege(currentUser.id, shipIdInt);


            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #6
0
        protected void AbandonColony()
        {
            if (Request.Params["colonyId"] == null)
            {
                return;
            }
            string colonyId = Request.Params["colonyId"];
            int    colonyIdInt;

            if (!Int32.TryParse(colonyId, out colonyIdInt))
            {
                return;
            }


            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp = bc.AbandonColony(Int32.Parse(userId), colonyIdInt);

            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #7
0
        protected void joinAlliance()
        {
            System.IO.StreamReader reader3 = new System.IO.StreamReader(Request.InputStream);
            string allianceId = reader3.ReadToEnd();
            int    allianceIdInt;

            if (!Int32.TryParse(allianceId, out allianceIdInt))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            resp += bc.joinAlliance(currentUser.id, allianceIdInt);

            /*
             *
             * try
             * {
             *  // 2. Open the connection
             *  conn.Open();
             *
             *  string query = "[dbo].[joinAlliance]";
             *  SqlCommand cmd = new SqlCommand(query, conn);
             *  cmd.CommandType = CommandType.StoredProcedure;
             *
             *  SqlParameter userIdParameter = new SqlParameter();
             *  userIdParameter.ParameterName = "@userId";
             *  userIdParameter.Value = userId;
             *  cmd.Parameters.Add(userIdParameter);
             *
             *  SqlParameter allianceIdParam = new SqlParameter();
             *  allianceIdParam.ParameterName = "@allianceId";
             *  allianceIdParam.Value = allianceIdInt;
             *  cmd.Parameters.Add(allianceIdParam);
             *
             *  SqlParameter param2 = new SqlParameter("@output1", SqlDbType.Int);
             *  param2.Direction = ParameterDirection.Output;
             *  cmd.Parameters.Add(param2);
             *
             *  cmd.ExecuteNonQuery();
             *  resp += param2.Value.ToString();
             *  conn.Close();
             *
             * }
             * finally
             * {
             *  if (conn != null)
             *  {
             *      conn.Close();
             *  }
             * }
             */

            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #8
0
        protected void sendShipRefit()
        {
            StreamReader reader3     = new StreamReader(Request.InputStream);
            string       transferXML = reader3.ReadToEnd();

            xmlCheckOk = true;
            //string transferXML = Request.InputStream;

            try
            {
                StringReader      textReader = new StringReader(transferXML);
                XmlReaderSettings settings   = new XmlReaderSettings();

                string x = Request.PhysicalPath;
                x = x.Substring(0, x.Length - "Ships.aspx".Length);
                x = x + "ShipRefit.xsd";
                settings.Schemas.Add(null, x);
                settings.XmlResolver             = null;
                settings.MaxCharactersInDocument = 10000;
                settings.ValidationType          = ValidationType.Schema;
                settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(transferSettingsValidationEventHandler);
                // Successfully parse the file, otherwise an XmlException is to be thrown
                XmlReader reader = XmlReader.Create(textReader, settings);
                try
                {
                    //just check it
                    while (reader.Read())
                    {
                        ;
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception source: {0}", e.Source);
                return;
            }

            if (xmlCheckOk == false)
            {
                return;
            }


            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp = bc.shipRefit(currentUser.id, transferXML);

            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
        protected void questRead()
        {
            if (Request.Params["questId"] == null)
            {
                return;
            }
            string questId = Request.Params["questId"];
            int    questIdInt;

            if (!Int32.TryParse(questId, out questIdInt))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            bc.setQuestRead(currentUser.id, questIdInt);

            /*
             * try
             * {
             *  // 2. Open the connection
             *  conn.Open();
             *  // 3. Pass the connection to a command object
             *  //BUG//string query = "exec [dbo].[Movement] @shipId ,@currentUserSession, @direction,@duration,@output";
             *  string query = "[quests].[questRead]";
             *  SqlCommand cmd = new SqlCommand(query, conn);
             *  cmd.CommandType = CommandType.StoredProcedure;
             *
             *
             *  SqlParameter param1 = new SqlParameter();
             *  param1.ParameterName = "@userId";
             *  param1.Value = currentUser.id;
             *  cmd.Parameters.Add(param1);
             *
             *  SqlParameter param2 = new SqlParameter();
             *  param2.ParameterName = "@questId";
             *  param2.Value = questIdInt;
             *  cmd.Parameters.Add(param2);
             *
             *  //cmd.ExecuteNonQuery();
             *
             *  conn.Close();
             * }
             * finally
             * {
             *  // Close the connection
             *  if (conn != null)
             *  {
             *      conn.Close();
             *  }
             * }
             */
            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #10
0
        public void getCommNodeMessageTest()
        {
            instance.commNodes.First().Value.commNodeMessages.Clear();
            instance.identities.commNodeMessage.id = 0;

            //create user
            User user = Mock.mockGeneratedUser(instance);
            List <SpacegameServer.BC.XMLGroups.CommNode> commNodes = SpacegameServer.BC.XMLGroups.CommNodes.createKnownAndNearNodesList(user);

            var node = commNodes.First().node;

            //create ship
            SpacegameServer.Core.ShipBuild builder = new ShipBuild(instance);
            int          newShipId      = (int)instance.identities.shipLock.getNext();
            ShipTemplate template       = instance.shipTemplate.Where(e => e.Value.hullid == 1).First().Value;
            var          targetRegionId = GeometryIndex.calcRegionId(node.positionX, node.positionY);
            Field        field          = GeometryIndex.regions[targetRegionId].findOrCreateField(node.positionX, node.positionY);
            Colony       colony         = Mock.mockColony(ColonyUserId: user.id);
            Ship         newShip        = builder.buildShip(newShipId, template, field, user.id, colony, false);

            //add user to commNode
            node.checkAndAddUser(user, newShip);

            node.sendCommMessage(user, "head1", "body1");
            node.sendCommMessage(user, "head2", "body2");


            SpacegameServer.BC.BusinessConnector bc = new SpacegameServer.BC.BusinessConnector();
            string ret = bc.getCommNodeMessage(user.id, node.id, 0, 50);

            string expected = @"<messages>
  <message>
    <id>2</id>
    <commNodeId>" + node.id.ToString() + @"</commNodeId>
    <sender>" + user.id.ToString() + @"</sender>
    <headline>head2</headline>
    <messageBody>body2</messageBody>
    <sendingDate>2015-07-08T20:48:43.2544728Z</sendingDate>
    <newMessage>0</newMessage>
  </message>
  <message>
    <id>1</id>
    <commNodeId>" + node.id.ToString() + @"</commNodeId>
    <sender>1</sender>
    <headline>head1</headline>
    <messageBody>body1</messageBody>
    <sendingDate>2015-07-08T20:48:43.2464723Z</sendingDate>
    <newMessage>0</newMessage>
  </message>
</messages>";

            //sendingDate can't be tested, since it is set to Now()
            // so only the first few lines are compared
            ret      = String.Join("", ret.Split(new[] { '\r', '\n' }).Where((e, i) => i < 14));
            expected = String.Join("", expected.Split(new[] { '\r', '\n' }).Where((e, i) => i < 14));
            Assert.AreEqual(expected, ret);
        }
Example #11
0
        protected string didYouKnow()
        {
            //string version = EmpiresInSpace.Core.
            //string version = DateTime.Now.ToString();
            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            Users user = (Users)Session["user"];

            return(bc.getLabel(user.id, 1029)); //didYouKnow
        }
        public static void ClassInit(TestContext context)
        {
            instance = Core.Instance;
            bc       = new SpacegameServer.BC.BusinessConnector();

            DataConnector connector = new EmptyDataConnector();

            instance.dataConnection = connector;
        }
Example #13
0
        protected void createAlliance()
        {
            if (Request.Params["newName"] == null)
            {
                return;
            }
            string newName = Request.Params["newName"];

            newName = Helpers.StripUserHtml(newName);

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            resp += bc.createAlliance(currentUser.id, newName);

            /*
             * try
             * {
             *  // 2. Open the connection
             *  conn.Open();
             *
             *  string query = "[dbo].[createAlliance]";
             *  SqlCommand cmd = new SqlCommand(query, conn);
             *  cmd.CommandType = CommandType.StoredProcedure;
             *
             *  SqlParameter userIdParameter = new SqlParameter();
             *  userIdParameter.ParameterName = "@userId";
             *  userIdParameter.Value = userId;
             *  cmd.Parameters.Add(userIdParameter);
             *
             *  SqlParameter newNameParameter = new SqlParameter();
             *  newNameParameter.ParameterName = "@allianceName";
             *  newNameParameter.Value = newName;
             *  cmd.Parameters.Add(newNameParameter);
             *
             *  SqlParameter param2 = new SqlParameter("@xml", SqlDbType.Xml);
             *  param2.Direction = ParameterDirection.Output;
             *  cmd.Parameters.Add(param2);
             *
             *  cmd.ExecuteNonQuery();
             *  resp += param2.Value.ToString();
             *  conn.Close();
             *
             * }
             * finally
             * {
             *  if (conn != null)
             *  {
             *      conn.Close();
             *  }
             * }
             */
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #14
0
        protected void selfDestruct()
        {
            if (Request.Params["shipId"] == null)
            {
                return;
            }
            string shipId = Request.Params["shipId"];
            int    shipIdInt;

            if (!Int32.TryParse(shipId, out shipIdInt))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp += bc.shipSelfdestruct(currentUser.id, shipIdInt);

            /*
             * try
             * {
             *  conn.Open();
             *
             *  SqlCommand cmd = new SqlCommand("[dbo].[selfDestruct]", conn);
             *  cmd.CommandType = CommandType.StoredProcedure;
             *
             *  SqlParameter userIdParameter = new SqlParameter();
             *  userIdParameter.ParameterName = "@userId";
             *  userIdParameter.Value = userId;
             *  cmd.Parameters.Add(userIdParameter);
             *
             *  SqlParameter templateIdParameter = new SqlParameter("shipId", SqlDbType.Int);
             *  templateIdParameter.Value = shipIdInt;
             *  cmd.Parameters.Add(templateIdParameter);
             *
             *  cmd.ExecuteNonQuery();
             *
             *  conn.Close();
             * }
             * finally
             * {
             *  // Close the connection
             *  if (conn != null)
             *  {
             *      conn.Close();
             *  }
             * }
             */
            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #15
0
 private bool Registeruser(int demoUserId, string startingRegion = null)
 {
     SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
     if (bc.userRegisterUser(demoUserId, startingRegion, true))
     {
         this.SetSession(demoUserId);
         Response.Redirect("Galaxy.aspx");
         return(true);
     }
     return(false);
 }
        protected void getReceivedmessages()
        {
            if (Request.Params["fromNr"] == null)
            {
                return;
            }
            string fromNr = Request.Params["fromNr"];

            if (Request.Params["toNr"] == null)
            {
                return;
            }
            string toNr = Request.Params["toNr"];


            if (Request.Params["messageHighestId"] == null)
            {
                return;
            }
            string messageHighestId = Request.Params["messageHighestId"];
            int    x;
            int    y;
            int    z;

            if (!Int32.TryParse(fromNr, out x) || !Int32.TryParse(toNr, out y) || !Int32.TryParse(messageHighestId, out z))
            {
                return;
            }

            if (Request.Params["messageType"] == null)
            {
                return;
            }
            string messageType = Request.Params["messageType"];
            int    messageTypeInt;

            if (!Int32.TryParse(messageType, out messageTypeInt))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp += bc.getReceivedMessages(currentUser.id, x, y, z, messageTypeInt);


            Response.Clear();
            Response.StatusCode  = 200;
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
            return;
        }
Example #17
0
        protected string didYouKnowFact()
        {
            //string version = EmpiresInSpace.Core.
            //string version = DateTime.Now.ToString();
            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            Users user = (Users)Session["user"];

            Random rand      = new Random();
            int    randomInt = (int)Math.Floor(rand.NextDouble() * 8.0);

            return(bc.getLabel(user.id, 1030 + randomInt));
        }
Example #18
0
        public void BCMovePathTest()
        {
            string ret = "";

            SpacegameServer.BC.BusinessConnector bc;
            bc = new SpacegameServer.BC.BusinessConnector();

            Ship newShip = Mock.mockShip();

            newShip.systemid   = null;
            newShip.max_hyper  = 10;
            newShip.max_impuls = 10;
            newShip.hyper      = 10;
            newShip.impuls     = 10;

            var OldPositionX = newShip.field.x;

            List <int> shipIds = new List <int>();

            shipIds.Add(newShip.id);
            List <byte> directions = new List <byte>();

            directions.Add(6);
            directions.Add(6);
            ret = bc.MovePathFleet(shipIds, directions, newShip.userid, 1);

            //deserialize MovePathResult
            SpacegameServer.BC.XMLGroups.MovePathResult movePathResult = null;
            System.Xml.Serialization.XmlSerializer      serializer     = new System.Xml.Serialization.XmlSerializer(typeof(SpacegameServer.BC.XMLGroups.MovePathResult));
            using (System.IO.TextReader reader = new System.IO.StringReader(ret))
            {
                movePathResult = (SpacegameServer.BC.XMLGroups.MovePathResult)serializer.Deserialize(reader);
            }

            //deserialize the first string
            SpacegameServer.BC.XMLGroups.MoveResultTree moveResult = null;
            serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpacegameServer.BC.XMLGroups.MoveResultTree));
            using (System.IO.TextReader reader = new System.IO.StringReader(movePathResult.StepResults[0]))
            {
                moveResult = (SpacegameServer.BC.XMLGroups.MoveResultTree)serializer.Deserialize(reader);
            }

            Assert.AreEqual(1, moveResult.result);
            Assert.AreEqual(OldPositionX + 1, moveResult.ships.First(ship => ship.id == newShip.id).posX, "Step 1 : wrong X coords");


            using (System.IO.TextReader reader = new System.IO.StringReader(movePathResult.StepResults[1]))
            {
                moveResult = (SpacegameServer.BC.XMLGroups.MoveResultTree)serializer.Deserialize(reader);
            }
            Assert.AreEqual(1, moveResult.result);
            Assert.AreEqual(OldPositionX + 2, moveResult.ships.First(ship => ship.id == newShip.id).posX, "Step 2 : wrong X coords");
        }
Example #19
0
        public void doBCResearch2Test()
        {
            User user = Mock.mockGeneratedUser(Instance);

            user.researchPoints = 100;
            user.PlayerResearch.Add(new UserResearch(user.id, 400));

            int      researchId = 501; //9, 501
            Research research   = Instance.Researchs[researchId];

            research.cost = 100;
            Assert.IsTrue(user.canResearch(research), "Player should be able to research 9");

            Assert.IsTrue(user.PlayerResearch.Count == 2);
            Assert.IsTrue(user.quests.Count == 0);
            Assert.IsTrue(user.researchPoints == 100);

            string ret = "";

            SpacegameServer.BC.BusinessConnector bc;
            bc  = new SpacegameServer.BC.BusinessConnector();
            ret = bc.doResearch(user.id, research.id);

            Assert.IsTrue(user.researchPoints == 0, "Player should not have any research points left");
            Assert.IsTrue(user.PlayerResearch.Count == 3, "Player should now have a second research");

            Assert.AreEqual(@"<ResearchDone>
  <Researches>
    <PlayerResearch>
      <id>11</id>
      <researchable>1</researchable>
      <isCompleted>0</isCompleted>
      <investedResearchpoints>0</investedResearchpoints>
      <researchPriority>0</researchPriority>
    </PlayerResearch>
  </Researches>
  <allowedBuildings />
  <ShipHulls>
    <ShipHull>
      <shipHullId>199</shipHullId>
    </ShipHull>
  </ShipHulls>
  <allowedModules>
    <allowedModule>
      <allowedModuleId>499</allowedModuleId>
    </allowedModule>
  </allowedModules>
</ResearchDone>", ret, "Return string is not as expected");

            //Assert.IsTrue(user.canResearch(research));
        }
        protected void getGameData()
        {
            string resp;

            resp = "<?xml version='1.0' encoding='utf-8' ?>";

            /*
             *      try
             *      {
             *          // 2. Open the connection
             *          conn.Open();
             *
             *          string query = "[dbo].[getGameData]";
             *          SqlCommand cmd = new SqlCommand(query, conn);
             *          cmd.CommandType = CommandType.StoredProcedure;
             *
             *          SqlParameter param5 = new SqlParameter("@xml", SqlDbType.Xml);
             *          param5.Direction = ParameterDirection.Output;
             *          cmd.Parameters.Add(param5);
             *
             *          cmd.ExecuteNonQuery();
             *          resp += param5.Value.ToString();
             *
             *
             *          conn.Close();
             *
             *      }
             *      finally
             *      {
             *          // Close the connection
             *          if (conn != null)
             *          {
             *              conn.Close();
             *          }
             *      }
             *
             */

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            string gameData = bc.getGameData();

            resp += gameData;


            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
        } // end

        protected void sendCommMessage()
        {
            if (Request.Params["commNode"] == null)
            {
                return;
            }
            string commNode = Request.Params["commNode"];


            int x;

            if (!Int32.TryParse(commNode, out x))
            {
                return;
            }


            string messageHeader = "";

            if (Request.Params["messageHeader"] != null)
            {
                messageHeader = Request.Params["messageHeader"];
            }



            StreamReader reader3        = new StreamReader(Request.InputStream);
            string       messageContent = reader3.ReadToEnd();


            //messageContent = Server.HtmlEncode(messageContent);

            messageContent = messageContent.Replace("\r\n", "<br />")
                             .Replace(Environment.NewLine, "<br />")
                             .Replace("\n", "<br />");

            messageContent = Helpers.StripUserHtml(messageContent);


            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp += bc.sendCommNodeMessage(currentUser.id, Int32.Parse(commNode), messageHeader, messageContent);


            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        } // end
Example #22
0
        protected void Transfer2()
        {
            //{"Sender":2,"Target":5,"SenderType":1,"TargetType":2,"Goods":[{"Id":1,"Qty":5},{"Id":3,"Qty":15},{"Id":2015,"Qty":6}]}
            //{"Sender":27,"SenderType":2,"Target":89,"TargetType":1,"Goods":[{"Id":1,"Qty":-10},{"Id":5,"Qty":10},{"Id":10,"Qty":-10}]}

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            string transferXML;

            try
            {
                StreamReader reader3 = new StreamReader(Request.InputStream);
                transferXML = reader3.ReadToEnd();
            }
            catch (Exception e)
            {
                bc.Log(e.ToString());
                return;
            }

            System.Web.Script.Serialization.JavaScriptSerializer ser = new System.Web.Script.Serialization.JavaScriptSerializer();


            SpacegameServer.Core.Transfer records;
            try
            {
                records = ser.Deserialize <SpacegameServer.Core.Transfer>(transferXML);
            }
            catch (Exception e)
            {
                bc.Log(e.ToString());
                return;
            }

            int userIdI;

            if (!Int32.TryParse(userId, out userIdI))
            {
                return;
            }


            resp += bc.transfer2(userIdI, records);

            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        }
Example #23
0
        protected void Application_Start(object sender, EventArgs e)
        {
            string path = Server.MapPath("~/");

            SpacegameServer.BC.BusinessConnector bc = SpacegameServer.SpaceServer.createServer();

            Application["bs"] = bc;

            Game.Instance.bc = bc;

            SpacegameServer.Core.Core.Instance.SendEvent       = EmpiresInSpace.SocketOut.sendEvent;
            SpacegameServer.Core.Core.Instance.RefreshShip     = EmpiresInSpace.SocketOut.RefreshShips;
            SpacegameServer.Core.Core.Instance.SendShip        = EmpiresInSpace.SocketOut.SendShip;
            SpacegameServer.Core.Core.Instance.SendCommMessage = EmpiresInSpace.SocketOut.SendCommMessage;
            SpacegameServer.Core.Core.Instance.SendMessage     = EmpiresInSpace.SocketOut.SendMessage;
            SpacegameServer.Core.Core.Instance.SendCombat      = EmpiresInSpace.SocketOut.SendCombat;
            SpacegameServer.Core.Core.Instance.SendNewTrade    = EmpiresInSpace.SocketOut.SendNewTrade;
            SpacegameServer.Core.Core.Instance.DeleteTrade     = EmpiresInSpace.SocketOut.DeleteTrade;
        }
Example #24
0
        protected void SendShipRepair(string shipId)
        {
            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            int shipInt = 0;

            Int32.TryParse(shipId, out shipInt);
            int userInt = 0;

            Int32.TryParse(userId, out userInt);

            resp = bc.ShipRepair(shipInt, userInt);

            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        } // end of colonize()
Example #25
0
        private bool DemoLoginCreate(int demoUserId)
        {
            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];
            //check if demoUser is really part of the game. If not, go to user creation routine
            if (bc.UserExists(demoUserId))
            {
                LoginDemoUser(demoUserId);
                return(true);
            }
            else
            {
                var StartingRegion = Application["StartingRegion"];
                if (Registeruser(demoUserId, StartingRegion != null ? StartingRegion.ToString() : null))
                {
                    return(true);
                }
            }

            return(false);
        }
        protected void getCombatMessages()
        {
            if (Request.Params["fromNr"] == null)
            {
                return;
            }
            string fromNr = Request.Params["fromNr"];

            if (Request.Params["toNr"] == null)
            {
                return;
            }
            string toNr = Request.Params["toNr"];


            if (Request.Params["messageHighestId"] == null)
            {
                return;
            }
            string messageHighestId = Request.Params["messageHighestId"];
            int    x;

            if (!Int32.TryParse(fromNr, out x) || !Int32.TryParse(toNr, out x) || !Int32.TryParse(messageHighestId, out x))
            {
                return;
            }

            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp = bc.getCombatMessages(currentUser.id, Int32.Parse(fromNr), Int32.Parse(toNr), Int32.Parse(messageHighestId));

            //return the result (Response)
            Response.Clear();
            Response.Expires = -1;
            //Response.ContentType = "text/xml";
            Response.Write(resp);
        } // end of
        } // end of

        protected void getCombatMessageRounds()
        {
            if (Request.Params["combatId"] == null)
            {
                return;
            }
            string combatId = Request.Params["combatId"];

            int x;

            if (!Int32.TryParse(combatId, out x))
            {
                return;
            }
            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp = bc.getCombatRounds(currentUser.id, x);

            //return the result (Response)
            Response.Clear();
            Response.Expires = -1;
            //Response.ContentType = "text/xml";
            Response.Write(resp);
        } // end of
        protected void getMessagesText()
        {
            if (Request.Params["messageId"] == null)
            {
                return;
            }
            string messageId = Request.Params["messageId"];

            int messageIdInt = 0;

            if (Int32.TryParse(messageId, out messageIdInt))
            {
                SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

                resp += bc.getMessagesText(currentUser.id, messageIdInt);
            }

            Response.Clear();
            Response.StatusCode  = 200;
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
            return;
        }
Example #29
0
 public void TestBCGameData()
 {
     //SpacegameServer.Core.Core Core = SpacegameServer.Core.Core.testCreateCore();
     SpacegameServer.BC.BusinessConnector bc = new SpacegameServer.BC.BusinessConnector();
     string test = bc.getGameData();
 }
        } // end of getReceivedmessages()

        //CommNodes::
        protected void getCommMessages()
        {
            if (Request.Params["commNode"] == null)
            {
                return;
            }
            string commNode = Request.Params["commNode"];


            if (Request.Params["fromNr"] == null)
            {
                return;
            }
            string fromNr = Request.Params["fromNr"];

            if (Request.Params["toNr"] == null)
            {
                return;
            }
            string toNr = Request.Params["toNr"];


            if (Request.Params["messageHighestId"] == null)
            {
                return;
            }
            string messageHighestId = Request.Params["messageHighestId"];
            int    x;

            if (!Int32.TryParse(fromNr, out x) || !Int32.TryParse(toNr, out x) || !Int32.TryParse(messageHighestId, out x) || !Int32.TryParse(commNode, out x))
            {
                return;
            }


            /*
             * int lastMessageId = 0;
             *
             * if (Session["messageHighestId"] != null)
             * {
             *  lastMessageId = (int)Session["messageHighestId"];
             * }
             */

            /*
             * try
             * {
             *  // 2. Open the connection
             *  conn.Open();
             *  // 3. Pass the connection to a command object
             *  //BUG//string query = "exec [dbo].[Movement] @shipId ,@currentUserSession, @direction,@duration,@output";
             *  string query = "[dbo].[getCommunicationMessage]";
             *  SqlCommand cmd = new SqlCommand(query, conn);
             *  cmd.CommandType = CommandType.StoredProcedure;
             *
             *
             *  SqlParameter param1 = new SqlParameter();
             *  param1.ParameterName = "@userId";
             *  param1.Value = currentUser.id;
             *  cmd.Parameters.Add(param1);
             *
             *  SqlParameter param1_2 = new SqlParameter();
             *  param1_2.ParameterName = "@commNodeId";
             *  param1_2.Value = commNode;
             *  cmd.Parameters.Add(param1_2);
             *
             *  SqlParameter param2 = new SqlParameter();
             *  param2.ParameterName = "@fromNr";
             *  param2.Value = fromNr;
             *  cmd.Parameters.Add(param2);
             *
             *  SqlParameter param3 = new SqlParameter();
             *  param3.ParameterName = "@toNr";
             *  param3.Value = toNr;
             *  cmd.Parameters.Add(param3);
             *
             *  SqlParameter param5 = new SqlParameter();
             *  param5.ParameterName = "@lastMessageId";
             *  if (messageHighestId != "0")
             *      param5.Value = messageHighestId;
             *  else
             *      param5.Value = DBNull.Value;
             *  cmd.Parameters.Add(param5);
             *
             *  SqlParameter param6 = new SqlParameter("@xml", SqlDbType.Xml);
             *  param6.Direction = ParameterDirection.Output;
             *  cmd.Parameters.Add(param6);
             *
             *
             *  cmd.ExecuteNonQuery();
             *  resp += param6.Value.ToString();
             *
             *  conn.Close();
             * }
             * finally
             * {
             *  // Close the connection
             *  if (conn != null)
             *  {
             *      conn.Close();
             *  }
             * }
             */


            SpacegameServer.BC.BusinessConnector bc = (SpacegameServer.BC.BusinessConnector)Application["bs"];

            resp += bc.getCommNodeMessage(currentUser.id, Int32.Parse(commNode), Int32.Parse(fromNr), Int32.Parse(toNr));

            //return the result (Response)
            Response.Clear();
            Response.Expires     = -1;
            Response.ContentType = "text/xml";
            Response.Write(resp);
        } // end of