Interservers are easy, just use a mysql database accessible to all the involved servers to put messages in, and retrieve them from module heartbeats and broadcast to the player or channel specified - doesn't have to be a linux server. Portalling doesn't even require nwnx. Here's our portal command:
} else if (GetStringLeft(sCText, 7) == "portal ") {
DeleteLocalString(oCPC, "FKY_CHAT_LOCAL_CTEXT");
int nServer;
sCText = GetStringRight(sCText, GetStringLength(sCText) - 7);
if (GetIsInCombat(oCPC) && !VerifyDMKey(oCPC) && !VerifyAdminKey(oCPC)) {
FloatingTextStringOnCreature(COLOR_RED + "You cannot portal during combat!" + COLOR_END, oCPC, FALSE);
return;
}
if (sCText == "here")
nServer = StringToInt(GetLocalString(GetModule(), "ServerNumber"));
else
nServer = StringToInt(sCText);
if (nServer < 110 || nServer > 999) {
FloatingTextStringOnCreature(COLOR_RED + "You cannot portal to that server!" + COLOR_END, oCPC, FALSE);
return;
}
SQLExecDirect("SELECT srv_id, srv_utime, srv_addr, srv_port FROM server_list WHERE srv_id = " + IntToString(nServer) +
" AND srv_utime + 60 >= (UNIX_TIMESTAMP() - srv_btime)");
if (SQLFetch() != SQL_SUCCESS) {
FloatingTextStringOnCreature(COLOR_RED + "That server is not active!" + COLOR_END, oCPC, FALSE);
return;
}
if (!VerifyAdminKey(oCPC) && StringToInt(SQLGetData(2)) < 60) {
FloatingTextStringOnCreature(COLOR_RED + "That server has not been up for a minute yet!" + COLOR_END, oCPC, FALSE);
return;
}
string sAddr = SQLGetData(3) + ":" + SQLGetData(4);
FloatingTextStringOnCreature(COLOR_GREEN + "Portaling you to " + sAddr + "!" + COLOR_END, oCPC, FALSE);
ActivatePortal(oCPC, sAddr, "", "", FALSE);
SetPlotFlag(oCPC, FALSE);
}
The servers are distinguished using the get port portion of the ip, which DOES require nwnx. The set a local on the server as it loads, so that all the servers can run the same version of the module. On pulling up the code to post it, I see we no longer do it that way. Instead, we now read from a file using another nwnx function, though we still do use the SQL code to check ip. Either way, if you're linking different ips, or if you just want to manaully enter the data in script for all the servers, you don't need this command - it just allows us to drop and add servers without recoding anything. Here's the load code, in two parts:
string sSQL, sServerNumber = FileReadAll("serverid.txt");
int nServerNumber = StringToInt(sServerNumber);
if (nServerNumber >= 100) {
sServerNumber = IntToString(nServerNumber);
} else {
string sServerIP;
sSQL = "select substring_index(user(), '@', -1) as ip;";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
sServerIP = SQLGetData(1);
else
sServerIP == "";
sServerNumber = GetStringRight(sServerIP, 3);
nServerNumber = StringToInt(sServerNumber);
}
if ((nServerNumber >= 100) && (nServerNumber <= 999)) {
WriteTimestampedLogEntry("running as server " + sServerNumber + " (module object " + ObjectToString(GetModule()) + ")");
SetLocalString(OBJECT_SELF, "ServerNumber", sServerNumber);
} else {
WriteTimestampedLogEntry("Error finding server ip!");
nServerNumber = 101;
sServerNumber = "101";
SetLocalString(OBJECT_SELF, "ServerNumber", "101");
}
if (nServerNumber % 10 == 9) {
SetLocalInt(oMod, "FKY_CHAT_ENABLE_PARTY_TO_AREA", 1);
SetLocalInt(oMod, "FKY_CHAT_ENABLE_SHOUT_TO_AREA", 1);
SetLocalInt(oMod, "FKY_CHAT_ENABLE_TELL_OOC_PREFIX", 1);
SetLocalInt(oMod, "FKY_CHAT_DISALLOW_SPEECH_WHILE_DEAD", 1);
SetLocalInt(oMod, "FKY_CHAT_DISALLOW_SPEECH_WHILE_SILENCED", 1);
}
Here's part 2:
if (SQLFetch() == SQL_SUCCESS) {
string sBootTime = SQLGetData(1);
string sServerAddr = FileReadAll("serveraddr.txt");
string sServerPort = FileReadAll("serverport.txt");
if (StringToInt(sServerPort) < 5000)
sServerPort = "512" + IntToString(nServerNumber % 10);
SetLocalInt(oMod, "boottime", StringToInt(sBootTime));
SetLocalString(oMod, "ServerAddr", sServerAddr);
SetLocalString(oMod, "ServerPort", sServerPort);
SQLExecDirect("REPLACE INTO server_list (srv_id, srv_btime, srv_utime, srv_memory, srv_players, srv_addr, srv_port, srv_last) VALUES ('"
+ sServerNumber + "', " + sBootTime + ", 0, 0, 0, '" + sServerAddr + "', " + sServerPort + ", NOW())");
}
LMK if you have any questions.
Funky
Modifié par FunkySwerve, 01 novembre 2011 - 06:14 .