Example #1
0
        private bool ICreateRelationship(uint parent, uint child, uint saver)
        {
            pnSqlInsertStatement insert = new pnSqlInsertStatement();
            insert.AddValue("ParentIdx", parent);
            insert.AddValue("ChildIdx", child);
            insert.AddValue("SaverIdx", saver);
            insert.Table = "NodeRefs";

            try {
                insert.Execute(fDb);
                return true;
            } catch (pnDbException e) {
                Error(e, String.Format("Failed to CreateRelationship {0}->{1}", parent, child));
                return false;
            }
        }
Example #2
0
        private void ICreateNode(pnVaultNode node)
        {
            pnSqlInsertStatement insert = new pnSqlInsertStatement();
            pnVaultNodeFields allFields = node.Fields;
            for (ulong bit = 1; bit != 0 && bit <= (ulong)allFields; bit <<= 1) {
                pnVaultNodeFields thisField = allFields & (pnVaultNodeFields)bit;
                if ((int)thisField == 0) continue;

                // Some basic sanity checks...
                switch (thisField) {
                    case pnVaultNodeFields.CreateTime:
                        // I don't care what we were told, it was created NOW
                        insert.AddValue("CreateTime", DateTime.UtcNow);
                        continue;
                    case pnVaultNodeFields.ModifyTime:
                        // I don't care what we were told, it was last modified NOW
                        insert.AddValue("ModifyTime", DateTime.UtcNow);
                        continue;
                    case pnVaultNodeFields.NodeIdx:
                        // Impossible.
                        continue;
                }

                string colName = thisField.ToString();
                insert.AddValue(colName, node[thisField]);
            }

            // We absolutely must have a correct Create/Modify time
            if (node[pnVaultNodeFields.CreateTime] == null)
                insert.AddValue("CreateTime", DateTime.UtcNow);
            if (node[pnVaultNodeFields.ModifyTime] == null)
                insert.AddValue("ModifyTime", DateTime.UtcNow);

            insert.Table = "Nodes";
            insert.Execute(fDb);
            node.NodeID = pnDatabase.LastInsert(fDb);
        }
Example #3
0
        static void IAddAccount(string[] args)
        {
            if (args.Length < 2) {
                Console.WriteLine("Usage: addacct <username> <password> [permissions]");
                Console.Write("Valid Permissions:");

                string[] perms = Enum.GetNames(typeof(pnAcctPerms));
                foreach (string perm in perms)
                    Console.Write(" " + perm);
                Console.WriteLine();
                return;
            }

            // Get our permissions
            int oPerm = (int)pnAcctPerms.Explorer;
            Guid oGuid = Guid.NewGuid();
            if (args.Length > 2) {
                try {
                    oPerm = (int)Enum.Parse(typeof(pnAcctPerms), args[2], true);
                } catch (ArgumentException) {
                    Console.WriteLine(String.Format("Error: Undefined permission level '{0}'", args[2]));
                    return;
                }
            }

            try {
                IDbConnection db = pnDatabase.Connect();

                // Check to see if this account already exists
                pnSqlSelectStatement check = new pnSqlSelectStatement();
                check.AddColumn("Guid");
                check.AddWhere("Username", args[0]);
                check.Limit = 1;
                check.Table = "Accounts";
                IDataReader r = check.Execute(db);
                if (r.Read()) {
                    Console.WriteLine(String.Format("Account already exists! [GUID: {0}]", r[0]));
                    r.Close();
                    return;
                } else r.Close();

                // Alright, we can add us an account
                pnSqlInsertStatement create = new pnSqlInsertStatement();
                create.AddValue("Username", args[0]);
                create.AddValue("Password", pnHelpers.GetString(pnHelpers.HashLogin(args[0], args[1])));
                create.AddValue("Permissions", oPerm);
                create.AddValue("Guid", oGuid);
                create.Table = "Accounts";
                create.Execute(db);
            } catch (pnDbException e) {
                Console.WriteLine("---Database Error---");
                Console.WriteLine(e.ToString());
            }
        }
Example #4
0
        private void ICreatePlayer()
        {
            pnCli2Vault_PlayerCreateRequest req = new pnCli2Vault_PlayerCreateRequest();
            req.Read(fStream);
            Debug(String.Format("Creating a Player: [N: {0}] [S: {1}]", req.fPlayerName, req.fShape));

            // Go ahead and init the response
            pnVault2Cli_PlayerCreateReply reply = new pnVault2Cli_PlayerCreateReply();
            reply.fTransID = req.fTransID;
            reply.fResult = ENetError.kNetSuccess;
            reply.fPlayerName = req.fPlayerName;
            reply.fShape = req.fShape;

            // Search for a matching PlayerInfo
            // We check the entire vault because we want to include deleted players as well.
            pnVaultPlayerInfoNode pi = new pnVaultPlayerInfoNode();
            pi.PlayerName = req.fPlayerName;
            try {
                if (IFindNode(pi.BaseNode).Length != 0) {
                    reply.fResult = ENetError.kNetErrPlayerAlreadyExists;
                    reply.Send(fStream);
                    return;
                }
            } catch (pnDbException e) {
                Error(e, "Create Player: FindNode Failed");
                reply.fResult = ENetError.kNetErrInternalError;
                reply.Send(fStream);
                return;
            }

            // Prepare the core node
            pnVaultPlayerNode player = new pnVaultPlayerNode();
            player.AccountUuid = req.fAcctGuid;
            player.AvatarShape = req.fShape;
            player.CreatorUuid = req.fAcctGuid;
            player.PlayerName = req.fPlayerName;

            // Go ahead and insert this node.
            try {
                ICreateNode(player.BaseNode);
                reply.fPlayerID = player.NodeID;
            } catch (pnDbException e) {
                Error(e, "Create Player: Couldn't create the PlayerNode");
                reply.fResult = ENetError.kNetErrInternalError;
                reply.Send(fStream);
                return;
            }

            // Player Info
            pnVaultPlayerInfoNode info = new pnVaultPlayerInfoNode();
            info.CreatorID = player.NodeID;
            info.CreatorUuid = req.fAcctGuid;
            info.PlayerID = player.NodeID;
            info.PlayerName = req.fPlayerName;

            try {
                ICreateNode(info.BaseNode);
            } catch (pnDbException e) {
                Error(e, "Create Player: Couldn't create the PlayerInfoNode");
                reply.fResult = ENetError.kNetErrInternalError;
                reply.Send(fStream);
                return;
            }

            // SimpleStdNodes
            uint? agejourn = ICreateStdNode(EStandardNode.kAgeJournalsFolder, player.NodeID, req.fAcctGuid);
            uint? agesicanvisit = ICreateStdNode(EStandardNode.kAgesICanVisitFolder, player.NodeID, req.fAcctGuid);
            uint? agesiown = ICreateStdNode(EStandardNode.kAgesIOwnFolder, player.NodeID, req.fAcctGuid);
            uint? avcloset = ICreateStdNode(EStandardNode.kAvatarClosetFolder, player.NodeID, req.fAcctGuid);
            uint? avoutfit = ICreateStdNode(EStandardNode.kAvatarOutfitFolder, player.NodeID, req.fAcctGuid);
            uint? buddies = ICreateStdNode(EStandardNode.kBuddyListFolder, player.NodeID, req.fAcctGuid);
            uint? chrons = ICreateStdNode(EStandardNode.kChronicleFolder, player.NodeID, req.fAcctGuid);
            uint? ignore = ICreateStdNode(EStandardNode.kIgnoreListFolder, player.NodeID, req.fAcctGuid);
            uint? inbox = ICreateStdNode(EStandardNode.kInboxFolder, player.NodeID, req.fAcctGuid);
            uint? recent = ICreateStdNode(EStandardNode.kPeopleIKnowAboutFolder, player.NodeID, req.fAcctGuid);

            // Create the tree
            ICreateRelationship(player.NodeID, info.NodeID, player.NodeID);
            if (agejourn.HasValue)
                ICreateRelationship(player.NodeID, agejourn.Value, player.NodeID);
            if (agesicanvisit.HasValue)
                ICreateRelationship(player.NodeID, agesicanvisit.Value, player.NodeID);
            if (agesiown.HasValue)
                ICreateRelationship(player.NodeID, agesiown.Value, player.NodeID);
            if (avcloset.HasValue)
                ICreateRelationship(player.NodeID, avcloset.Value, player.NodeID);
            if (avoutfit.HasValue)
                ICreateRelationship(player.NodeID, avoutfit.Value, player.NodeID);
            if (buddies.HasValue)
                ICreateRelationship(player.NodeID, buddies.Value, player.NodeID);
            if (chrons.HasValue)
                ICreateRelationship(player.NodeID, chrons.Value, player.NodeID);
            if (ignore.HasValue)
                ICreateRelationship(player.NodeID, ignore.Value, player.NodeID);
            if (recent.HasValue)
                ICreateRelationship(player.NodeID, recent.Value, player.NodeID);

            // Link to the System Node
            pnVaultSystemNode sys = new pnVaultSystemNode();
            uint[] systems = IFindNode(sys.BaseNode);
            if (systems.Length == 0)
                Warn("Hmmm... Where's the system node?");
            else {
                if (systems.Length > 1)
                    Warn("Hmmm... We have multiple system nodes. How did that happen?");
                ICreateRelationship(player.NodeID, systems[0], player.NodeID);
            }

            // Add to the players table...
            // First, we need to figure out what our account ID is
            pnSqlSelectStatement selAcctId = new pnSqlSelectStatement();
            selAcctId.AddColumn("Idx");
            selAcctId.AddWhere("Guid", req.fAcctGuid.ToString());
            selAcctId.Limit = 1;
            selAcctId.Table = "Accounts";
            try {
                IDataReader rsaid = selAcctId.Execute(fDb);
                if (rsaid.Read()) {
                    // Now, actually insert
                    uint acctIdx = Convert.ToUInt32(rsaid[0]);
                    rsaid.Close();

                    pnSqlInsertStatement insPlayer = new pnSqlInsertStatement();
                    insPlayer.AddValue("AcctIdx", acctIdx);
                    insPlayer.AddValue("PlayerIdx", player.NodeID);
                    insPlayer.AddValue("Name", req.fPlayerName);
                    insPlayer.AddValue("Model", req.fShape);
                    insPlayer.Table = "Players";
                    insPlayer.Execute(fDb);
                } else {
                    Warn(String.Format("HACK??? New player [#{0}] created for AcctGuid [{1}] not in our Accounts",
                        player.NodeID, req.fAcctGuid));
                    rsaid.Close();
                }
            } catch (pnDbException e) {
                Error(e, "Failed to add to Players table");
            } catch (Exception e) {
                Error(e, "Hmmm...");
            }

            // TODO: Add to AllPlayers Folder
            //       Implement me when we can notify clients about node adds.

            // TODO: Initialize core ages
            // Neighborhood, Ae'gura

            // Send the response :)
            reply.Send(fStream);
        }