Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PACKAGE START -----------
- package tribeHook
- {
- function gameConnection::autoAdminCheck(%this)
- {
- %p = parent::autoAdminCheck(%this);
- if(!tribeContainer.initialized)
- {
- if(discoverFile("config/server/Tribes/TribeContainer/tribeContainer.cs"))
- {
- //Tribe container file exists, let's load it up.
- exec("config/server/Tribes/TribeContainer/tribeContainer.cs");
- echo("Initialized the tribe container.");
- }
- else
- {
- //First time running this script, we need to create and save the new tribecontainer
- new scriptGroup(tribeContainer);
- tribeContainer.save("config/server/Tribes/TribeContainer/tribeContainer.cs");
- echo("First time initializing the tribe container: Success.");
- }
- tribeContainer.initialized = true;
- }
- %path = "config/server/Tribes/Users/" @ %this.bl_id @ ".txt";
- if(discoverFile(%path))
- {
- %f = new fileObject();
- %f.openForRead(%path);
- %tribe = %f.readLine();
- //To deal with user name changes or whatever..
- %userName = %f.readLine();
- %f.close();
- %f.delete();
- %this.tribe = tribeContainer.getTribeByName(%tribe);
- //Did we get an invalid tribe
- if(!%this.tribe)
- {
- error("Tribe invalid! Deleting user data associated with that Tribe.");
- %this.tribe = "";
- fileDelete(%path);
- }
- else
- {
- %this.tribe.add(%this);
- echo("Added user " @ %this.name @ " to Tribe " @ %this.getTribeName() @ " successfully.");
- }
- }
- return %p;
- }
- }; activatePackage(tribeHook);
- //PACKAGE END -----------
- //TRIBECONTAINER FUNCTIONS START -----------
- //Assuming the host will only be able
- //to create new tribes
- function tribeContainer::newTribe(%this,%name)
- {
- %c = %this.getCount();
- for(%i=0;%i<%c;%i++)
- {
- %tribeObj = %this.getObject(%i);
- if(%tribeObj.name $= %name)
- {
- //Already a tribe with that name.. end function
- return false;
- }
- }
- %newTribe = new simSet()
- {
- name = %name;
- //owner = ??
- //other data you want to store.
- };
- %this.add(%newTribe);
- %this.save("config/server/Tribes/TribeContainer/tribeContainer.cs");
- echo("New tribe " @ %name @ " added to Tribe container.");
- return %newTribe;
- }
- //Using this function will throw errors if users are still
- //Associated to this tribe, so make sure the tribe is empty.
- function tribeContainer::removeTribe(%this,%name)
- {
- %c = %this.getCount();
- for(%i=0;%i<%c;%i++)
- {
- %tribeObj = %this.getObject(%i);
- if(%tribeObj.name $= %name)
- {
- %tribeObj.delete();
- echo("Successfully deleted Tribe " @ %name);
- %this.save("config/server/Tribes/TribeContainer/tribeContainer.cs");
- return true;
- }
- }
- error("Could not find a Tribe object with the name " @ %name);
- return false;
- }
- function tribeContainer::getTribeByName(%this,%tribeName)
- {
- %c = %this.getCount();
- for(%i=0;%i<%c;%i++)
- {
- %tribeObj = %this.getObject(%i);
- if(%tribeObj.name $= %tribeName)
- {
- return %tribeObj;
- }
- }
- return false;
- }
- //TRIBECONTAINER FUNCTIONS END -----------
- //GAMECONNECTION FUNCTIONS START -----------
- function gameConnection::addToTribe(%this,%name)
- {
- //Tribe simset..
- %ss = tribeContainer.getTribeByName(%name);
- //No valid simset object supplied
- if(!isObject(%ss))
- {
- error("We need a valid simset object for Tribe named " @ %name @ ".");
- return false;
- }
- //User has a tribe already..
- if(isObject(%this.getTribe()))
- {
- error("This user is already in a tribe.");
- return false;
- }
- %this.tribe = %ss;
- //Save tribe info for a user to load upon joining the server
- %f = new fileObject();
- %f.openForWrite("config/server/Tribes/Users/" @ %this.bl_id @ ".txt");
- %f.writeLine(%ss.name);
- %f.writeLine(%this.name);
- %f.close();
- %f.delete();
- echo(%this.name @ " added to " @ %name @ " (" @ %ss @ ") successfully.");
- %ss.add(%this);
- return true;
- }
- function gameConnection::removeFromTribe(%this)
- {
- if(isObject(%this.tribe))
- {
- %tribe = %this.getTribe();
- %tribeName = %this.getTribeName();
- %tribe.remove(%this);
- %this.tribe = "";
- %res = fileDelete("config/server/Tribes/Users/" @ %this.bl_id @ ".txt");
- if(!%res)
- {
- error("No tribe file for " @ %this.name);
- return false;
- }
- else
- {
- echo("Removed " @ %this.name @ " from tribe " @ %tribeName);
- return true;
- }
- }
- else
- {
- error("This user is not in a tribe.");
- return false;
- }
- }
- function gameConnection::getTribe(%this)
- {
- //return the tribe however you're storing it
- //I'm just gunna assume it'll be tagged to the client
- return %this.tribe;
- }
- function gameConnection::getTribeName(%this)
- {
- return %this.tribe.name;
- }
- //GAMECONNECTION FUNCTIONS END
Advertisement
Add Comment
Please, Sign In to add comment