A Conversation for The H2G2 Programmers' Corner

I'm making an online community from scratch. Anyone want to help me?

Post 61

DoctorMO (Keeper of the Computer, Guru, Community Artist)

thank god for Ctr-C/V Ay?

Right, did someone order some code?

It only works for a DLL at the moement but you get the idea...

//Constants for InStrEx's IS_Mode Input
const long IS_Mode_For = 0; //Forwards
const long IS_Mode_Back = 1; //Backwards
const long IS_Mode_Number = 2; //Count/Number
const long IS_Mode_NoCase = 4; //Count/Number

BSTR _stdcall GarbageUp(BSTR Sentance, long Expereance)
{
int TmpInt, WordNum, i;
const char *TmpData;
CString Input, msgVal;

//Convert to standard CString (not so)
Input = (LPSTR)Sentance;

msgVal.Format("Input to Garbage: %s", Input);
MessageBox(NULL,msgVal,"Debugging",32);

//Set up random seed
Randomize();

//This is to make a relative number (Expereance% * Number of words)
TmpInt = (Expereance / 100) * InStrEx(0,Sentance,(BSTR)(LPSTR)" ",IS_Mode_Number,1);

for(i=1;i<=TmpInt;i++)
{
WordNum = ((rand()/255)*TmpInt-1)+1;
Sentance = SetArrayElement(Sentance,WordNum,(BSTR)(LPSTR)"Garbage",(BSTR)(LPSTR)" ");

}

return(SysAllocString(Sentance));

}

// ----------------------------------------------------
// FUNC: GetArrayElement
// DESC: This Function Selects a given element out
// of a string from the deliminator and the index
// RTRN: Function Returns String with array element
// DECL: (VB)
// Private Declare Function GetArrayElement Lib "SNVType.dll" (ByVal ArrayString As String, ByVal ArrayIndex As Integer, ByVal Deliminator As String) As Long
// ----------------------------------------------------

BSTR _stdcall GetArrayElement(BSTR ArrayString, long ArrayInput, BSTR Deliminator)
{
//--- Data Segment ---//
long Pos1, Pos2, Pos3, LastChar;
CString TmpStr, msgStr;
const char *OutData;
LPSTR VBVar;

//--- Code Segment ---//
TmpStr = (LPSTR)ArrayString;
//msgStr.Format("Input: %s",TmpStr);
//MessageBox(NULL,msgStr,"Input",32);

//Set Defaults
Pos1 = 0;
Pos2 = 0;
Pos3 = 0;
LastChar = 0;

//Loop for...
do {
//Position 1 is the first element deliminator
Pos1 = TmpStr.Find((LPSTR)Deliminator,Pos1+1);

if(Pos1<0) { Pos1=strlen(TmpStr); LastChar=1; }

//msgStr.Format("Loop Index: %d \nRequested Index: %d\nWord Position1: %d \n Word Position2: %d",Pos3,ArrayInput,Pos1,Pos2);
//MessageBox(NULL,msgStr,"Que",32);

//Check Position 3 against index
if(Pos3==ArrayInput)
{
//Get Element String Using Position 1 as
//The End and Position 2 as the start
TmpStr=TmpStr.Mid(Pos2,Pos1-Pos2);

//msgStr.Format("Cutting From: %d, To: %d, Length: %d \n String: %s",Pos1,Pos2,Pos1-Pos2-1,TmpStr);
//MessageBox(NULL,msgStr,"Pos1",32);

//Exit the loop, for we have what we want
goto ExitDo;
}
//Update Position 2 for which will
//be after Position 1 deliminator
Pos2=Pos1+strlen((LPSTR)Deliminator);
//Add to Position 3, the index counter
Pos3++;

} while (Pos3<ArrayInput+1&&LastChar==0);
//... As long as Position 3 is less than index

TmpStr="";

ExitDo:

if(TmpStr=="")
{
//Return Null
return(SysAllocString((BSTR)""));
goto ExitSelElement;
}

//Convert Value to
//BSTR again for VB
OutData=TmpStr;

//msgStr.Format("Return Value: %s",OutData);
//MessageBox(NULL,msgStr,"Return",32);

VBVar = (LPSTR)OutData;
//Return BSTR Value after a bit of C-Style Casting
return(SysAllocString((BSTR)VBVar));


ExitSelElement:;

}

// ----------------------------------------------------
// FUNC: SetArrayElement
// DESC: This Function Selects a given element out
// of a string from the deliminator and the index
// RTRN: Function Returns String with replaced array element
// DECL: (VB)
// Private Declare Function SetArrayElement Lib "SNVType.dll" (ByVal ArrayString As String, ByVal ArrayIndex As Integer, BtVal WithString As String, ByVal Deliminator As String) As Long
// ----------------------------------------------------

BSTR _stdcall SetArrayElement(BSTR ArrayString, long ArrayInput, BSTR WithString, BSTR Deliminator)
{
//--- Data Segment ---//
long Pos1, Pos2, Pos3, LastChar;
CString TmpStr, msgStr, TmpWith;
const char *OutData;
LPSTR VBVar;

//--- Code Segment ---//
TmpStr = (LPSTR)ArrayString;
TmpWith = (LPSTR)WithString;
//msgStr.Format("Input: %s",TmpStr);
//MessageBox(NULL,msgStr,"Input",32);

//Set Defaults
Pos1 = 0;
Pos2 = 0;
Pos3 = 0;
LastChar = 0;

//Loop for...
do {
//Position 1 is the first element deliminator
Pos1 = TmpStr.Find((LPSTR)Deliminator,Pos1+1);

if(Pos1<0) { Pos1=strlen(TmpStr); LastChar=1; }

//msgStr.Format("Loop Index: %d \nRequested Index: %d\nWord Position1: %d \n Word Position2: %d",Pos3,ArrayInput,Pos1,Pos2);
//MessageBox(NULL,msgStr,"Que",32);

//Check Position 3 against index
if(Pos3==ArrayInput)
{
//Get Element String Using Position 1 as
//The End and Position 2 as the start
TmpStr=TmpStr.Left(Pos2) + TmpWith + TmpStr.Right(strlen(TmpStr)-Pos1);

//msgStr.Format("Cutting From: %d, To: %d, Length: %d \n String: %s",Pos1,Pos2,Pos1-Pos2-1,TmpStr);
//MessageBox(NULL,msgStr,"Pos1",32);

//Exit the loop, for we have what we want
goto ExitDo;
}
//Update Position 2 for which will
//be after Position 1 deliminator
Pos2=Pos1+strlen((LPSTR)Deliminator);
//Add to Position 3, the index counter
Pos3++;

} while (Pos3<ArrayInput+1&&LastChar==0);
//... As long as Position 3 is less than index

TmpStr="";

ExitDo:

if(TmpStr=="")
{
//Return Null
return(SysAllocString((BSTR)""));
goto ExitSelElement;
}

//Convert Value to
//BSTR again for VB
OutData=TmpStr;

//msgStr.Format("Return Value: %s",OutData);
//MessageBox(NULL,msgStr,"Return",32);

VBVar = (LPSTR)OutData;
//Return BSTR Value after a bit of C-Style Casting
return(SysAllocString((BSTR)VBVar));


ExitSelElement:;

}

//This function sets the random seed
//the the current PC time, wich sould
//stop any repeated values on start up.
void Randomize( void )
{
time_t b;
int iInput;

//Get time value
iInput = time(&b);
srand(iInput);
}

// ----------------------------------------------------
// FUNC: InStrEx
// DESC: This Function Gets a SearchString and searches for
// SearchFor String, when found it will count down
// until it reaches the result you want and will even
// count the number of times it apears
// Declare each value with ByVal in VB! With thanks
// To Martin Owens for this function.
// RTRN: Function Returns Long Pointer to were the search
// Item was found, or in the case of IS_MODE_COUNT
// The number of items found.
// DECL: (VB)
// Private Declare Function InStrEx Lib "SNVType.dll" (ByVal StartPos As Long, ByVal SearchString As String, ByVal SearchFor As String, ByVal IS_Mode As Long, ByVal ChrNumber As Long) As Long
// ----------------------------------------------------

long _stdcall InStrEx( long StartPos, BSTR SearchString, BSTR SearchFor, long IS_Mode , long ChrNumber )
{
int Z, ChrSteping, ChrFrom, ChrTo;
CString Str1, String1, String2, tmpStr;
long CN, tmpOut, SaftyLoop;

CN = ChrNumber;

if(CN == 0)
{
CN = 1;
}

CN--;

String1 = (CString)(LPSTR)SearchString;
String2 = (CString)(LPSTR)SearchFor;

//Error Message Index
//
// General Error -1
// Is Mode Error -2
// Start Position -3
// Chracictor Number -4
// To many loops -5

if(IS_Mode2) { return(-2); goto ExitInStrEx; }
if(StartPosstrlen(String1)-1) { return(-3); goto ExitInStrEx; }

if(IS_Mode == 0) {

ChrSteping = 1;
if(StartPos == 0)
StartPos = 1;

ChrFrom = StartPos;
ChrTo = strlen(String1);

} else { if(IS_Mode == 1) {

ChrSteping = -1;
if((StartPos == 0))
StartPos = strlen(String1);

ChrFrom = StartPos;
ChrTo = 1;

} else { if(IS_Mode == 2) {

if(ChrNumber==0){ return(-4); goto ExitInStrEx; }

ChrSteping = 1;
ChrFrom = StartPos;
ChrTo = strlen(String1);
}}}

tmpOut = 0;
SaftyLoop = 0;

for(Z = ChrFrom; Z != ChrTo + 1; Z+= ChrSteping)
{

Str1 = String1.Mid((Z - 1), strlen(String2));


if(Str1 == String2)
{

if(IS_Mode == 2)
{
tmpOut++;
} else {
tmpOut = Z;

if(CN == 0)
{
return(tmpOut);
goto ExitInStrEx;
} else {
CN--;
}
}
}

SaftyLoop++;

int tmpint;
tmpint = strlen(String1) + 1;

if(SaftyLoop > tmpint)
{
return(-5);
goto ExitInStrEx;
}

}

//ReturnNull:;

tmpOut=-1;

return(tmpOut);

ExitInStrEx:;

}

-- DoctorMO --


I'm making an online community from scratch. Anyone want to help me?

Post 62

Calculator Nerd 256

Wow. What's it do?
smiley - geek >8^B


I'm making an online community from scratch. Anyone want to help me?

Post 63

26199

Oops, I missed that hwen you first posted it smiley - headhurts

Thanks - I'll take a proper look at it tomorrow when I've had some sleep smiley - smiley


I'm making an online community from scratch. Anyone want to help me?

Post 64

26199

*When* you first posted it...

See what lack of sleep can do to a man... smiley - biggrin


I'm making an online community from scratch. Anyone want to help me?

Post 65

DoctorMO (Keeper of the Computer, Guru, Community Artist)

I hope it helps smiley - smiley

-- DoctorMO --


I'm making an online community from scratch. Anyone want to help me?

Post 66

Calculator Nerd 256

I figured it out. I want it to be like a combination Project Ego and The Sims, except that the first people there are the first people on the entire planet, with no civilization or even any plants to start with, just some dirt, rocks, plants that are still seeds, and all of the animals to start with are born the moment the first set of people get there... or we could run a year's worth of simulation before putting anyone there, or maybe a couple centuries to get all the trees just right. But one thing: it MUST not be arbitrarily chosen by us where things start, there should be a definite mathematical algorithm for the seemingly random placement of all life. I can't stand when programmers/designers play God and choose everything, like the Sphere Grid in FFX.
*catches breath*
Whew, what a rant.
I'm done for now, except to ask what you were talking about "when you first posted it." What did I post when?
smiley - geek >8^B


I'm making an online community from scratch. Anyone want to help me?

Post 67

26199

When DoctorMO first posted the code...

It's actually very easy to do what that code does in Java... just use a StringTokeniser to split the String up into an array of Strings, then alter the ones you want, and finally concatenate the whole lot to form one String...

The key part is the transformation from an English word to one in a fictional language - it needs to be the same every time for a particular word, and it needs to end up seeming like a real language.

The system I have working at the moment:

- replaces specific various vowel and consonant combinations with different ones chosen to form a realistic language

- rates the difficulty of each word and only scrambles those that are too difficult

- alters the order of words, preserving sentence structure

- supports multiple (currently five) distinct languages

I'm not sure if the final version will work like this - but I'm working on other aspects of the game at the moment. There's a whole lot still to do...


I'm making an online community from scratch. Anyone want to help me?

Post 68

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Sounds nice, if you wanted a 'lanuage' set up it must require lots of tables.

-- DoctorMO --


I'm making an online community from scratch. Anyone want to help me?

Post 69

26199

Joeh - res at beasmj emeet bajmj er yecasemiesl yeslesesm lyen mo ler... Ler jaopeyapasms yeslesesms ajanajeel sese af bele ef eilbaaj lossail... Jaopeyapasms ban anad ler beo beyamfe-beer nedal... Y leoedad ler jaopeyapasms nedafl ajanajeel.

At'gaja s mdaaj joo lao mo fet bet an, me mo resail smiley - smiley


I'm making an online community from scratch. Anyone want to help me?

Post 70

26199

Oops, wrong language smiley - winkeye

Yeah - it has about twenty or thirty consonant combinations to scan for... replacements for individual consonants if none of those suggest anything... then replacements for every possible two-vowel pair... followed by replacements for individual vowels.

It's kinda dull trying to fill that lot in, to be honest smiley - smiley


I'm making an online community from scratch. Anyone want to help me?

Post 71

DoctorMO (Keeper of the Computer, Guru, Community Artist)

There is an easier way, develop an alerithem to convert 'selected' words into nonsense and just have an input to which langage and how much of it to convert. I'm sure it could be easy.

-- DoctorMO --


I'm making an online community from scratch. Anyone want to help me?

Post 72

Calculator Nerd 256

couple of questions:
a)Why do we need a language thing? We could just make up a few languages and speak in them whenever we go there so that people would want to learn them. I have an article somewhere that you can get to from my personal space about Chibee, a made up language I am fluent in.
2)Wat's all this "Awaiting Moderation" jazz? That is so unhoopy. Are they trying to shut our forum down? If so, there zarking with the wrong froods! ...J/K
smiley - geek>8^B


I'm making an online community from scratch. Anyone want to help me?

Post 73

26199

Ah, but the point is, it should be realistic... and a good step towards realism is having each English word map to an equivalent in the fictional language. Just replacing some words with random garbage is a little easier, but a lot less realistic...

And it's for my text-based game, Calculator Nerd smiley - smiley

The hidden posting is hidden because I posted it in one of the fictional languages smiley - laugh... it'll probably never be unhidden, because they'll never find anyone who can speak the language, since it's made up smiley - biggrin

It contains exactly the same text as the post after it, though, bar the 'oops, wrong language' smiley - smiley

smiley - laugh

I did wonder if that would happen smiley - smiley


I'm making an online community from scratch. Anyone want to help me?

Post 74

DoctorMO (Keeper of the Computer, Guru, Community Artist)

What did you do? convert, then show. and then convert back?

-- DoctorMO --


I'm making an online community from scratch. Anyone want to help me?

Post 75

26199

The hidden post, y'mean?

Nah, I just converted it then posted the original... hmm. I wonder how good the conversion back would be - it probably wouldn't be perfect, because I haven't worried about losing information. But I'd think you could get most of it...

Luckily that isn't a problem smiley - biggrin


I'm making an online community from scratch. Anyone want to help me?

Post 76

DoctorMO (Keeper of the Computer, Guru, Community Artist)

What about people who hack?
and Cheat?

-- DoctorMO --


I'm making an online community from scratch. Anyone want to help me?

Post 77

26199

Hmmm. Well, the code is only on the server... so they'd have to hack into the server and get access to the source to cheat that way. And I'm not sure it would help too much... since they'd then have to write a program to convert it back...

Cheating is another matter... I've tried to account for that... in general, the best way to cheat would be to separate each letter out like t h i s, so it thinks they're separate words... that way, since they're short, they're considered easier to understand... and won't be scrambled so often.

That, however, is an awful lot of work - and not in the spirit of the game. It should be fairly easy to spot...

And I plan on implementing IP and user based banning for anyone who tries to cheat... (well, IP banning is already there, user banning will come when there are users smiley - smiley)... maybe a 24 hour ban for a first offence smiley - biggrin


I'm making an online community from scratch. Anyone want to help me?

Post 78

Calculator Nerd 256

Okay, I'm a little slow here. The language thing is for the Java game right? Not the civilization client/game? Did I get it right this time?
smiley - geek>8^B


I'm making an online community from scratch. Anyone want to help me?

Post 79

Calculator Nerd 256

Also, if it's open source, what's to prevent people from making mods of it that let them get on the original server and mess up stuff like killing people? I guess we, and by "we" I mean Docmo, could find some way to make it so there are multiple worlds on multiple servers and each world is a different program so that if someone does make a mod, they'll have to find/make a server to host it
smiley - geek>8^B


I'm making an online community from scratch. Anyone want to help me?

Post 80

26199

That's right, it's for my game...

MUDs are based around a dumb-client kinda model... they don't do anything but send commands, and the server does all of the calculations, so there's no way to cheat like that...

However, you're right - for anything where the client is doing calculations, that becomes an issue. Not an easy one to solve, either...

I think they tend to use some kind of authentication procedure that checks what version is being used, so that someone can't connect with the wrong version...


Key: Complain about this post