Here's a system to link cd keys to playernames using the native bioware database.
When a character logs in, it will automatically check their cd key from oncliententer, and compare it to a Campaign variable stored in the database. If that variable is not set, this is the first time that playername has logged in (at least since this system was installed). The key will be linked to their account by setting that variable, and they can proceed with play as normal, unaware that anything has happened. If the variable is already set, however, and it does not match they key they are using, they are booted. This setup allows you to accumulate CD Key info as you go, and assumes that the first login of an account is ligit - an assumption that held true on our server. It's technically possible someone else could get to it first, but the chances are small, since most need to see the account name in use first in order to steal it (unless it's known already). Generally, I think this is far preferable to server passwording, as it's less of an impediment to players, an the chances of a non-legitimate first logger are quite small, and can be addressed as soon as the legitimate logger posts on the forums of your server reporting the account lockout.
This system is a little more complex than that, though. It also allows addition of multiple keys, up to 7, for a playername - you'd be amazed at how many players use more than one. On our server, it's done via a conversation fired from a item they get when they enter the docks. The conditional checks to make sure they don't already have 7 keys added (this one returns FALSE if they do).
int StartingConditional()
{
object oPC = GetPCSpeaker();
string sStoredKey = GetCampaignString("PlayernameKey", GetPCPlayerName(oPC));
if (sStoredKey != "") {
int nLength = GetStringLength(sStoredKey);
if (nLength > 65) /* allow 7 keys max SET-key-key-key-key-key-key-key SET/ADD + 7 spacers + 7x8 keys = 66 */
return FALSE;
}
return TRUE;
}
If they do not have the maximum allowed already, their account is marked as ready to accept a new key, and they are asked to logout, swap to the new key, and log in again. This is the action taken script for that line:
void main()
{
object oPC = GetPCSpeaker();
string sStoredKey = GetCampaignString("PlayernameKey", GetPCPlayerName(oPC));
string sKeys = "ADD" + GetStringRight(sStoredKey, GetStringLength(sStoredKey) - 3);//mark as adding
SetCampaignString("PlayernameKey", GetPCPlayerName(oPC), sKeys);
}
Here is the oncliententer code I mentioned at the outset, which should make more sense now that you know the procedure for adding keys:
int VerifyPlayernameAgainstCDKey(object oPlayer) {
int nBoot = FALSE;
string sPName = GetPCPlayerName(oPlayer);
string sKey = GetPCPublicCDKey(oPlayer);
string sNewKey, sAddingKey, sStoredKey = GetCampaignString("PlayernameKey", sPName);
/* there's at least one key stored already */
if (sStoredKey != "") {
sAddingKey = GetStringLeft(sStoredKey, 3);
sStoredKey = GetStringRight(sStoredKey, GetStringLength(sStoredKey) - 3);
/* they indicated that they wanted to add a key this login */
if (sAddingKey == "ADD") {
/* their current key is not in the key string, add it unless at 7 keys already */
if (FindSubString(sStoredKey, sKey) == -1) {
int nKeyLength = GetStringLength(sStoredKey);
/* allow 7 keys max SET-key-key-key-key-key-key-key SET/ADD + 7 spacers + 7x8 keys = 66 */
if (nKeyLength > 65) {
nBoot = TRUE;
/* must mark as no longer adding */
SetCampaignString("PlayernameKey", sPName, "SET" + sStoredKey);
/* add the key to the string */
} else {
sNewKey = "SET" + sStoredKey + "-" + sKey;
SetCampaignString("PlayernameKey", sPName, sNewKey);
DelayCommand(25.0, FloatingTextStringOnCreature("New CD Key Successfully Added!", oPlayer, FALSE));
}
/* let them know they already had this key in their string */
} else {
DelayCommand(25.0,
FloatingTextStringOnCreature("CD Key Addition Failed! This key already listed for this account!", oPlayer,
FALSE));
/* must mark as no longer adding */
SetCampaignString("PlayernameKey", sPName, "SET" + sStoredKey);
}
/* they are not adding, and the cd key doesnt match those listed - boot and log */
} else if (FindSubString(sStoredKey, sKey) == -1) {
string sReport = "INCORRECT CD KEY DETECTED! ID: " + sUnencoded + "; Name: " +
GetName(oPlayer) + "; CD Key: " + sKey + "; IP: " + GetPCIPAddress(oPlayer);
WriteTimestampedLogEntry(sReport);
SendMessageToAllDMs(sReport);
nBoot = TRUE;
}
/* new account, add the key */
} else {
SetCampaignString("PlayernameKey", sPName, "SET-" + sKey);
}
return nBoot;
}
void main() {
object oPC = GetEnteringObject();
/* verify CD keys and double logins to stop hackers */
if (VerifyPlayernameAgainstCDKey(oPC)) {
if (GetIsObjectValid(oPC))
BootPC(oPC);
return;
}
}
Funky
Modifié par FunkySwerve, 09 juillet 2011 - 03:43 .