Exemplo n.º 1
0
        /// <summary>
        /// Logs the memory useage using GC.GetTotalMemory and returns the memory useage
        /// </summary>
        /// <param name="p">Process to use to calculate memory</param>
        public static void LogMemory(Process p)
        {
            long mem = +GC.GetTotalMemory(false);

            if (mem > maxMemoryUseage)
            {
                maxMemoryUseage = mem;
            }
            Globals_Server.logEvent("GC memory: " + mem);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Send an update to the client- used when the message to be sent requires additional information other than just a response code and some strings
 /// </summary>
 /// <param name="message">Message to be sent- can contain any number of details</param>
 public void Update(ProtoMessage message)
 {
     Contract.Requires(message != null);
     message.ActionType = Actions.Update;
     if (conn != null)
     {
         Globals_Server.logEvent("Update " + this.username + ": " + message.ResponseType.ToString());
         Console.WriteLine("Sending update " + message.ResponseType.ToString() + " to " + this.username);
         Server.SendViaProto(message, conn, alg);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initialise the server, and store some test users and clients.
        /// </summary>
        private void initialise()
        {
            LogInManager.StoreNewUser("helen", "potato");
            LogInManager.StoreNewUser("test", "tomato");
            LogInManager.StoreNewUser("simon", "farshas");
            NetPeerConfiguration config = new NetPeerConfiguration(app_identifier);

            //config.BroadcastAddress = NetUtility.Resolve("* your external IP here in IPv4 format *"); // external IP of a machine that the server might be running on
            config.LocalAddress       = NetUtility.Resolve(host_name);
            config.MaximumConnections = max_connections;
            config.Port = port;
            config.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);
            config.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionLatencyUpdated, true);
            config.PingInterval      = 10f;
            config.ConnectionTimeout = 100f;
            server   = new NetServer(config);
            ctSource = new CancellationTokenSource();
            server.Start();
            Globals_Server.server = server;
            Globals_Server.logEvent("Server started- host: " + config.BroadcastAddress + ", port: " + port + ", appID: " +
                                    app_identifier + ", max connections: " + max_connections);
            Client client = new Client("helen", "Char_158");

            Globals_Server.Clients.Add("helen", client);
            Client client2 = new Client("test", "Char_196");

            Globals_Server.Clients.Add("test", client2);
            Client client3 = new Client("simon", "Char_283");

            Globals_Server.Clients.Add("simon", client3);
            String        dir = Directory.GetCurrentDirectory();
            List <string> pcs = Globals_Game.pcKeys;                 // to potentially add a "create user function"

            pcs.Remove("Char_158");
            pcs.Remove("Char_195");
            pcs.Remove("Char_283");
            //dir = dir.Remove(dir.IndexOf("RepairHist_mmo"));
            String path;

            if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
            {
                path = Path.Combine(dir, "Certificates");
            }
            else
            {
                dir  = Directory.GetParent(dir).FullName;
                dir  = Directory.GetParent(dir).FullName;
                dir  = Directory.GetParent(dir).FullName;
                path = Path.Combine(dir, "Certificates");
            }
            Diplomacy.forgeAlliance("Char_283", "Char_196");
            Diplomacy.declareWar("Char_283", "Char_158");
            LogInManager.InitialiseCertificateAndRSA(path);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Writes a Journal object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="key">Database key to use</param>
        /// <param name="journal">Journal to write</param>
        public static bool DatabaseWrite_Journal(string gameID, string key, Journal journal)
        {
            var rJournal         = new RiakObject(gameID, key, journal);
            var putJournalResult = Globals_Server.rClient.Put(rJournal);

            if (!putJournalResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Journal " + key + " to bucket " + rJournal.Bucket);
            }

            return(putJournalResult.IsSuccess);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Writes a Terrain object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="t">Terrain to write</param>
        public static bool DatabaseWrite_Terrain(string gameID, Terrain t)
        {
            var rTerrain         = new RiakObject(gameID, t.id, t);
            var putTerrainResult = Globals_Server.rClient.Put(rTerrain);

            if (!putTerrainResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Terrain " + rTerrain.Key + " to bucket " + rTerrain.Bucket);
            }

            return(putTerrainResult.IsSuccess);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes a Dictionary object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="key">Database key to use</param>
        /// <param name="dictionary">Dictionary to write</param>
        public static bool DatabaseWrite_Dictionary <T>(string gameID, string key, T dictionary)
        {
            var rDict         = new RiakObject(gameID, key, dictionary);
            var putDictResult = Globals_Server.rClient.Put(rDict);

            if (!putDictResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Dictionary " + key + " to bucket " + rDict.Bucket);
            }

            return(putDictResult.IsSuccess);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes a bool variable to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="key">Database key to use</param>
        /// <param name="thisBool">bool to write</param>
        public static bool DatabaseWrite_Bool(string gameID, string key, bool thisBool)
        {
            var rBool         = new RiakObject(gameID, key, thisBool);
            var putBoolResult = Globals_Server.rClient.Put(rBool);

            if (!putBoolResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Bool variable " + key + " to bucket " + rBool.Bucket);
            }

            return(putBoolResult.IsSuccess);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes a BaseLanguage object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="bl">BaseLanguage to write</param>
        public static bool DatabaseWrite_BaseLanguage(string gameID, BaseLanguage bl)
        {
            var rBaseLanguage         = new RiakObject(gameID, bl.id, bl);
            var putBaseLanguageResult = Globals_Server.rClient.Put(rBaseLanguage);

            if (!putBaseLanguageResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: BaseLanguage " + rBaseLanguage.Key + " to bucket " + rBaseLanguage.Bucket);
            }

            return(putBaseLanguageResult.IsSuccess);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Writes a Siege object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="s">Siege to write</param>
        public static bool DatabaseWrite_Siege(string gameID, Siege s)
        {
            var rSiege         = new RiakObject(gameID, s.siegeID, s);
            var putSiegeResult = Globals_Server.rClient.Put(rSiege);

            if (!putSiegeResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Siege " + rSiege.Key + " to bucket " + rSiege.Bucket);
            }

            return(putSiegeResult.IsSuccess);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Writes a Nationality object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="n">Nationality to write</param>
        public static bool DatabaseWrite_Nationality(string gameID, Nationality n)
        {
            var rNationality         = new RiakObject(gameID, n.natID, n);
            var putNationalityResult = Globals_Server.rClient.Put(rNationality);

            if (!putNationalityResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Nationality " + rNationality.Key + " to bucket " + rNationality.Bucket);
            }

            return(putNationalityResult.IsSuccess);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Writes an Army object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="a">Army to write</param>
        public static bool DatabaseWrite_Army(string gameID, Army a)
        {
            var rArmy         = new RiakObject(gameID, a.armyID, a);
            var putArmyResult = Globals_Server.rClient.Put(rArmy);

            if (!putArmyResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Army " + rArmy.Key + " to bucket " + rArmy.Bucket);
            }

            return(putArmyResult.IsSuccess);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Writes a Rank object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="r">Rank to write</param>
        public static bool DatabaseWrite_Rank(string gameID, Rank r)
        {
            var rRank         = new RiakObject(gameID, r.id.ToString(), r);
            var putRankResult = Globals_Server.rClient.Put(rRank);

            if (!putRankResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Rank " + rRank.Key + " to bucket " + rRank.Bucket);
            }

            return(putRankResult.IsSuccess);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Writes a VictoryData object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="vicDat">VictoryData to write</param>
        public static bool DatabaseWrite_VictoryData(string gameID, VictoryData vicDat)
        {
            var rVictoryData         = new RiakObject(gameID, vicDat.playerID, vicDat);
            var putVictoryDataResult = Globals_Server.rClient.Put(rVictoryData);

            if (!putVictoryDataResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: VictoryData " + rVictoryData.Key + " to bucket " + rVictoryData.Bucket);
            }

            return(putVictoryDataResult.IsSuccess);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Writes a newID variable to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="key">Database key to use</param>
        /// <param name="newID">newID to write</param>
        public static bool DatabaseWrite_newID(string gameID, string key, uint newID)
        {
            var rCharVar         = new RiakObject(gameID, key, newID);
            var putCharVarResult = Globals_Server.rClient.Put(rCharVar);

            if (!putCharVarResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: newID variable " + key + " to bucket " + rCharVar.Bucket);
            }

            return(putCharVarResult.IsSuccess);
        }
Exemplo n.º 15
0
        public static bool DatabaseWrite_Client(string gameID, Client client)
        {
            Client_Serialized clientSer = new Client_Serialized(client);
            var rString         = new RiakObject(gameID, client.username, clientSer);
            var putStringResult = Globals_Server.rClient.Put(rString);

            if (!putStringResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: String variable " + clientSer.user + " to bucket " + rString.Bucket);
            }

            return(putStringResult.IsSuccess);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Writes a GameClock object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="gc">GameClock to write</param>
        public static bool DatabaseWrite_Clock(string gameID, GameClock gc)
        {
            var rClock         = new RiakObject(gameID, "gameClock", gc);
            var putClockResult = Globals_Server.rClient.Put(rClock);

            if (!putClockResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: GameClock to bucket " + rClock.Bucket + ": " + putClockResult.ErrorMessage);
            }


            return(putClockResult.IsSuccess);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Writes a key list (List object) to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <par	am name="k">key of key list</param>
        /// <param name="kl">key list to write</param>
        public static bool DatabaseWrite_KeyList <T>(string gameID, string k, List <T> kl)
        {
            Console.WriteLine("Writing key list " + k + " to bucket " + gameID);
            RiakObject rList         = new RiakObject(gameID, k);
            var        putListResult = Globals_Server.rClient.Put(rList);

            if (!putListResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Key list " + rList.Key + " to bucket " + rList.Bucket);
            }

            return(putListResult.IsSuccess);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Writes a string variable to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="key">Database key to use</param>
        /// <param name="pcID">string to write</param>
        public static bool DatabaseWrite_String(string gameID, string key, string pcID)
        {
            pcID = "\"" + pcID + "\"";

            var rString         = new RiakObject(gameID, key, pcID);
            var putStringResult = Globals_Server.rClient.Put(rString);

            if (!putStringResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: String variable " + key + " to bucket " + rString.Bucket);
            }

            return(putStringResult.IsSuccess);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Updates the client
        /// </summary>
        /// <param name="message">The message code to send</param>
        /// <param name="fields">Additional information to add to the message</param>
        public void Update(DisplayMessages message, string[] fields = null)
        {
            ProtoMessage m = new ProtoMessage();

            m.ActionType    = Actions.Update;
            m.ResponseType  = message;
            m.MessageFields = fields;
            if (conn != null)
            {
                Globals_Server.logEvent("Update " + this.username + ": " + message.ToString());
                Console.WriteLine("Sending update " + message.ToString() + " to " + this.username);
                Server.SendViaProto(m, conn, alg);
            }
        }
Exemplo n.º 20
0
        public void ProcessMessage(global::ProtoMessage.ProtoMessage m, NetConnection connection)
        {
            Contract.Requires(connection != null && m != null);
            Client client;

            clientConnections.TryGetValue(connection, out client);
            if (client == null)
            {
                NetOutgoingMessage errorMessage =
                    server.CreateMessage("There was a problem with the connection. Please try re-connecting");
                server.SendMessage(errorMessage, connection, NetDeliveryMethod.ReliableOrdered);
                string log = "Connection from peer " + connection.Peer.UniqueIdentifier +
                             " not found in client connections. Timestamp: " +
                             DateTime.Now.ToString(DateTimeFormatInfo.CurrentInfo);
                Globals_Server.logError(log);
                return;
            }
            var pc = client.myPlayerCharacter;

            if (pc == null || !pc.isAlive)
            {
                NetOutgoingMessage msg = server.CreateMessage("You have no valid PlayerCharacter!");
                server.SendMessage(msg, connection, NetDeliveryMethod.ReliableOrdered);
                server.FlushSendQueue();
            }
            else
            {
                ProtoMessage forActionController = new ProtoMessage();
                string       responseType        = m.ResponseType.ToString();

                /*forActionController.ResponseType = responseType;
                 * ProtoMessage reply = Game.ActionController(m, client);
                 * // Set action type to ensure client knows which action invoked response
                 * if (reply == null)
                 * {
                 *  ProtoMessage invalid = new ProtoMessage(DisplayMessages.ErrorGenericMessageInvalid);
                 *  invalid.ActionType = Actions.Update;
                 *  reply = invalid;
                 * }
                 * else
                 * {
                 *  reply.ActionType = m.ActionType;
                 * }
                 * SendViaProto(reply, connection, true, client.alg);
                 * Globals_Server.logEvent("From " + clientConnections[connection] + ": request = " +
                 *                      m.ActionType.ToString() + ", reply = " + reply.ResponseType.ToString());*/
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Writes a Province or Province_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="p">Province to write</param>
        /// <param name="ps">Province_Serialised to write</param>
        public static bool DatabaseWrite_Province(string gameID, Province p = null, Province_Serialised ps = null)
        {
            if (p != null)
            {
                // convert Province into Province_Serialised
                ps = DatabaseWrite.Province_serialise(p);
            }

            var rProv         = new RiakObject(gameID, ps.id, ps);
            var putProvResult = Globals_Server.rClient.Put(rProv);

            if (!putProvResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Province " + rProv.Key + " to bucket " + rProv.Bucket);
            }

            return(putProvResult.IsSuccess);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Writes a Kingdom or Kingdom_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="k">Kingdom to write</param>
        /// <param name="ks">Kingdom_Serialised to write</param>
        public static bool DatabaseWrite_Kingdom(string gameID, Kingdom k = null, Kingdom_Serialised ks = null)
        {
            if (k != null)
            {
                // convert Kingdom into Kingdom_Serialised
                ks = DatabaseWrite.Kingdom_serialise(k);
            }

            var rKing         = new RiakObject(gameID, ks.id, ks);
            var putKingResult = Globals_Server.rClient.Put(rKing);

            if (!putKingResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Kingdom " + rKing.Key + " to bucket " + rKing.Bucket);
            }

            return(putKingResult.IsSuccess);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Writes a Position or Position_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="p">Position to write</param>
        /// <param name="ps">Position_Serialised to write</param>
        public static bool DatabaseWrite_Position(string gameID, Position p = null, Position_Serialised ps = null)
        {
            if (p != null)
            {
                // convert Position into Position_Serialised
                ps = DatabaseWrite.Position_serialise(p);
            }

            var rPos         = new RiakObject(gameID, ps.id.ToString(), ps);
            var putPosResult = Globals_Server.rClient.Put(rPos);

            if (!putPosResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Position " + rPos.Key + " to bucket " + rPos.Bucket);
            }

            return(putPosResult.IsSuccess);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Writes a Fief or Fief_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="f">Fief to write</param>
        /// <param name="fs">Fief_Serialised to write</param>
        public static bool DatabaseWrite_Fief(string gameID, Fief f = null, Fief_Serialised fs = null)
        {
            if (f != null)
            {
                // convert Fief to Fief_Serialised
                fs = DatabaseWrite.Fief_serialise(f);
            }

            var rFief         = new RiakObject(gameID, fs.id, fs);
            var putFiefResult = Globals_Server.rClient.Put(rFief);

            if (!putFiefResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Fief " + rFief.Key + " to bucket " + rFief.Bucket);
            }

            return(putFiefResult.IsSuccess);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Writes a HexMapGraph edges collection to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="map">HexMapGraph containing edges collection to write</param>
        /// <param name="edges">Edges collection to write</param>
        public static bool DatabaseWrite_MapEdges(string gameID, HexMapGraph map = null, List <TaggedEdge <string, string> > edges = null)
        {
            if (map != null)
            {
                // convert Language into Language_Serialised
                edges = DatabaseWrite.EdgeCollection_serialise(map.myMap.Edges.ToList());
            }

            var rMapE         = new RiakObject(gameID, "mapEdges", edges);
            var putMapResultE = Globals_Server.rClient.Put(rMapE);

            if (!putMapResultE.IsSuccess)
            {
                Globals_Server.logError("Write failed: Map edges collection " + rMapE.Key + " to bucket " + rMapE.Bucket);
            }

            return(putMapResultE.IsSuccess);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Processes a client disconnecting from the server- removes the client as an observer, removes their connection and deletes their CryptoServiceProvider
        /// </summary>
        /// <param name="conn">Connection of the client who disconnected</param>
        private void Disconnect(NetConnection conn)
        {
            Contract.Requires(conn != null);
            lock (ServerLock)
            {
                if (clientConnections.ContainsKey(conn))
                {
                    Client client = clientConnections[conn];
                    Globals_Server.logEvent("Client " + client.username + " disconnects");
                    Globals_Game.RemoveObserver(client);
                    client.conn = null;
                    clientConnections.Remove(conn);

                    client.alg = null;
                    conn.Disconnect("Disconnect");
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Writes a PlayerCharacter or PlayerCharacter_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="pc">PlayerCharacter to write</param>
        /// <param name="pcs">PlayerCharacter_Serialised to write</param>
        public static bool DatabaseWrite_PC(string gameID, PlayerCharacter pc = null, PlayerCharacter_Serialised pcs = null)
        {
            if (pc != null)
            {
                // convert PlayerCharacter into PlayerCharacter_Serialised
                pcs = DatabaseWrite.PC_serialise(pc);
            }

            // write PlayerCharacter_Serialised to database
            var rPC         = new RiakObject(gameID, pcs.charID, pcs);
            var putPCresult = Globals_Server.rClient.Put(rPC);

            if (!putPCresult.IsSuccess)
            {
                Globals_Server.logError("Write failed: PC " + rPC.Key + " to bucket " + rPC.Bucket);
            }

            return(putPCresult.IsSuccess);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Writes a NonPlayerCharacter or NonPlayerCharacter_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="npc">NonPlayerCharacter to write</param>
        /// <param name="npcs">NonPlayerCharacter_Serialised to write</param>
        public static bool DatabaseWrite_NPC(string gameID, NonPlayerCharacter npc = null, NonPlayerCharacter_Serialised npcs = null)
        {
            if (npc != null)
            {
                // convert NonPlayerCharacter into NonPlayerCharacter_Serialised
                npcs = DatabaseWrite.NPC_serialise(npc);
            }

            // write NonPlayerCharacter_Serialised to database
            var rNPC         = new RiakObject(gameID, npcs.charID, npcs);
            var putNPCresult = Globals_Server.rClient.Put(rNPC);

            if (!putNPCresult.IsSuccess)
            {
                Globals_Server.logError("Write failed: NPC " + rNPC.Key + " to bucket " + rNPC.Bucket);
            }

            return(putNPCresult.IsSuccess);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Writes a Language or Language_Serialised object to the database
        /// </summary>
        /// <returns>bool indicating success</returns>
        /// <param name="gameID">Game (bucket) to write to</param>
        /// <param name="l">Language to write</param>
        /// <param name="ls">Language_Serialised to write</param>
        public static bool DatabaseWrite_Language(string gameID, Language l = null, Language_Serialised ls = null)
        {
            if (l != null)
            {
                // convert Language into Language_Serialised
                ls = DatabaseWrite.Language_serialise(l);
            }

            // write Language_Serialised to database
            var rLanguage         = new RiakObject(gameID, ls.id, ls);
            var putLanguageResult = Globals_Server.rClient.Put(rLanguage);

            if (!putLanguageResult.IsSuccess)
            {
                Globals_Server.logError("Write failed: Language " + rLanguage.Key + " to bucket " + rLanguage.Bucket);
            }

            return(putLanguageResult.IsSuccess);
        }
Exemplo n.º 30
0
        public static void TestRun(bool encrypt = true)
        {
            Process currentProcess = Process.GetCurrentProcess();

            if (encrypt)
            {
                Globals_Server.logEvent("Running test with encryption");
            }
            else
            {
                Globals_Server.logEvent("Running test without encryption");
            }
            double LoginTime, RecruitTime, MoveTime, SpyTime;
            double start = DateTime.Now.TimeOfDay.TotalMilliseconds;

            byte[] encryptionKey = null;
            if (encrypt)
            {
                encryptionKey = LogInManager.GetRandomSalt(32);
            }
            client.LogInAndConnect(Username, Pass, encryptionKey);
            while (!client.IsConnectedAndLoggedIn())
            {
                Thread.Sleep(0);
            }
            LoginTime = DateTime.Now.TimeOfDay.TotalMilliseconds - start;
            client.RecruitTroops(OwnedArmy.armyID, 70, true);
            RecruitTime = ProcessNextAction(Actions.RecruitTroops, currentProcess);
            // Move to another fief
            client.Move(MyPlayerCharacter.charID, NotOwnedFief.id, null);
            MoveTime = ProcessNextAction(Actions.TravelTo, currentProcess);
            // Spy
            client.SpyOnFief(MyPlayerCharacter.charID, MyPlayerCharacter.location.id);
            SpyTime = ProcessNextAction(Actions.SpyFief, currentProcess);
            // Confirm spy
            Globals_Server.logEvent("Time taken to run test (ms): " + (DateTime.Now.TimeOfDay.TotalMilliseconds - start));
            Globals_Server.logEvent("LogIn time: " + LoginTime);
            Globals_Server.logEvent("Recruit time: " + (RecruitTime));
            Globals_Server.logEvent("Travel time: " + MoveTime);
            Globals_Server.logEvent("Spy time: " + SpyTime);
            Globals_Server.logEvent("Max memory measured: " + maxMemoryUseage);
        }