|
You last visited: Today at 02:42
Advertisement
Editing strings in a MySQL database in C#?
Discussion on Editing strings in a MySQL database in C#? within the CO2 Private Server forum part of the Conquer Online 2 category.
11/30/2012, 22:58
|
#1
|
elite*gold: 111
Join Date: Feb 2008
Posts: 2,161
Received Thanks: 646
|
Editing strings in a MySQL database in C#?
This is somewhat noobish, but I really can't figure this out.
I created a database entry in the character table that inserts strings into a field. Whenever you start a quest or progress in a quest it adds another string so that I can check for that on the next part of the quest. So, my problem.
For adding strings/checking it would be:
Code:
user.quests += "sss";
if (user.quests.contains("sss")
but I realize that running multiple if statements checking for values in this on an npc won't work, as it can only run one if-statement with a certain value and several strings will still be in the database that it has checked for before, so I have to have a way of removing or replacing it.
I tried:
Code:
user.quests -=(which doesn't work for strings), user.quest.remove("sss") // doesnt do anything
user.quest.replace("sss", "aaa") // doesn't do anything either.
.replace could probably work if i deleted text from a certain index( ), but that wont work as people wont do the quests in the same order, so I cant set it to a certain index without it being replaced at some point.
Any ideas? At the moment I can only add strings to it, but not remove.
|
|
|
11/30/2012, 23:22
|
#2
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
|
This is NOT how to handle this...
I cannot think of any more inefficient way to handle it to be honest (not to be rude... just a fact)
String comparisons are quite costly operations and scale horrendously poorly (might be 'acceptable' with a user having 5 quests but what if they have 100?)
A more scalable system would be a quests table following a structure somewhere along the line of...
PlayerID
QuestID
var1
var2
var3
CompletionEnum
That way you can do something like
SELECT * FROM QUESTS WHERE PlayerID=X AND CompletionEnum=Active
UPDATE QUESTS var1=mobKills WHERE PlayerID=X
Simple updates like that.
You then can do a QuestType table which links quest id to further information (times available, description, rewards, etc).
Break tables into their most simple yet functional format is generally the right course of action.
|
|
|
11/30/2012, 23:39
|
#3
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
Couldnt have said it better myself pro, that string system is such a fundamentally flawed system its not even funny =x
|
|
|
11/30/2012, 23:43
|
#4
|
elite*gold: 111
Join Date: Feb 2008
Posts: 2,161
Received Thanks: 646
|
I do appreciate the feedback, but I wasn't actually going to use this. I was doing this solely for learning. So I'd still like to have an answer from anyone who can bother.
|
|
|
12/01/2012, 00:09
|
#5
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
|
So you want to learn how to use a system which you will never use, and should never use in the future?
Why bother?
Sigh well in any case, .remove and .replace are doing something, but they return the new modified string, so you would need to do
Example = Example.Replace("sss", "yyy");
Intellisense is something you should be paying attention to while coding.
|
|
|
12/01/2012, 01:16
|
#6
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
|
Small example..
lets say you have a string variable as part of your character class called "QuestString".
When checking if you have a quest active you would have to do something like.
if(user.QuestString.Contains("UniqueQuestName"))
//logic
All of the string logic (adding new quests, removing old quests, checking if quest exists) should be done source side and the database value should only be referenced when loading the character and when saving to the database (when user logs out or server shuts down)
Keep in mind that such a string system is not only more computationally expensive the longer the string is (more characters to check) but you're also required to give quests a unique name.
EG:
QuestString = "PheasantHunting1PheasantHunting10"
These are two stages to one quest (lets assume you have 10 quests. just an example) but using
if(user.QuestString.Conatains("PheasantHunting1") will return quest even if you do not current have the first stage of the quest because PheasantHunting10 contains the string PheasantHunting1.
it's just a realllyyy bad approach.
|
|
|
12/01/2012, 01:26
|
#7
|
elite*gold: 0
Join Date: Mar 2005
Posts: 1,425
Received Thanks: 1,565
|
shouldnt you be using a enumeration like pro says. its cheaper for the CPU to process and its easier to handle...
Code:
Switch (user.Quest)
{
case UserQuest.PheasantHunting:
{
//code block here
break;
}
}
public enum UserQuest
{
None=0,
PheasantHunting=1,
DragonHunting=2
//etc etc
}
and if you want to store it into the database as a string for easy reading you could do
reading:
Code:
var datareader = new DataReader("SELECT quest FROM QUESTS WHERE PlayerID=X AND CompletionEnum=Active")
user.Quest = (UserQuest)Enum.parse(datareader["Quest"],typeof(UserQuest);
writing
Code:
sql.execute(string.format("Update Quests Set Quest='{0}' where PlayerID={1}",user.Quest.ToString(),User.ID);
Something like that
and in the database the value for PlayerID XXX should be the Enum Name.. i.e PheasantHunting
if you wanted each quest type to have different steps.. like stage1, stage2, stage 3 have another
you could do..
Code:
user.Quest = (FieldValue / 100);
user.QuestStage=(FieldValue % 100)
so if you was doing the pheasant quest and on stage 2 you would have in the database the ID 102
result being:
Code:
user.Quest = PheasantHunting
User.QuestStage = 2
its basic math, ill let you work out the rest.
|
|
|
12/01/2012, 17:43
|
#8
|
elite*gold: 150
Join Date: Apr 2010
Posts: 9,739
Received Thanks: 8,977
|
#Closed as requested
|
|
|
|
Similar Threads
|
[REQUEST]/[RELEASE] Database Game.exe Editing
07/30/2011 - Shaiya - 3 Replies
First off want to point out the rules
Do you need Shaiya Hacks, Bots, Cheats or anything else?
Take a look here
Ok So this is not a Question it is a Request.
Also for This
I won't post a question or other non-releases in this forum.
|
Database strings
07/17/2011 - Rappelz - 7 Replies
I got a question about strings stored in the database. I was trying to insert new places into the teleport npcs and also tried to correct those "empty string" shop npcs, that are in the latest server release.
First lets start off with the teleporter.
I edited "NPC Teleport Town (2455194ffb3cb3515526cb9e195a8371).lua"
and inserted new location in the Asura Katan teleporter. I tried these 4:
dlg_menu( "@90700000", 'RunTeleport( 100000 , 219257 , 15681 )' ) --Lost Mine 1
dlg_menu(...
|
[Help] account mysql database
07/03/2009 - CO2 Private Server - 2 Replies
i was wondering if anyone could help me i have tq binarys database jsut curious
Account Table= 8146
Char Table=4448
how do i delete the 4k unused accounts?
|
[HELP] MySql Database
12/09/2008 - CO2 Private Server - 0 Replies
Mysql database keeps giving an error:
PHPMYADMIN ERROR, The server isn't reacting.
What should i do lol, i've re-installed it like 3 times still doesn't work. Hm...
Ciao!
|
'' MySQL database ''
11/10/2008 - Conquer Online 2 - 8 Replies
How do i let my friend connect to my MYSQL database so he can also be a hoster and create accounts.
Any 1 idea's post em here
Regards Memos ,
|
All times are GMT +2. The time now is 02:42.
|
|