16
Drivers / Re: MySQL on MudOS/FluffOS
« on: November 11, 2008, 05:51:36 pm »
Hi all! I've released my SQL daemon code for the DS lib here, if anyone wants to port it to his or her lib

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Using this significantly increased memory usage on my testserver (about 50MB more at startup).
Does anyone else see anything like that?
Something I had planned to do on my mud was to modify my lib to implement three dimensional mapping system for room code which would have allowed me to flesh out ranged combat and area based effects.I believe Crat is doing something to that extent.
sudo apt-get install build-essential bison libc6-dev
should do it. build-essential includes gcc, etc.
new_side["Desc"] = mp["desc"];
RetMap["desc"] = Sides[side]["Desc"];
//Get the shortened description ("desc" in the door mapping) for use in verbose room exits. If not, use "door"
string GetDesc(string side) {
if( !side) { /* let's hack a side */
object room;
if( !this_player() ) room = previous_object();
else room = environment(this_player());
foreach(string s, class door_side val in Sides) {
side = s;
if( member_array(room, val->Rooms) != -1 ) break;
}
}
if( stringp(((class door_side)Sides[side])->Desc) )
return ((class door_side)Sides[side])->Desc;
else return "door";
}
mixed Desc;
#define COLORIZED_EXITS 1
#define VERBOSE_EXITS 1
//Use this to get whether or not an exit is obvious.
int GetExitObv( string str ) {
if( !Exits[str] ) return 0;
else return Exits[str]["obv"];
}
//Use this or GetFullExitData to get a mapping of obvious or not, to use for visible/invisible doors in lib/std/room.c
mapping GetObvMap() {
mapping ret = ([]);
foreach(string key in keys(Exits)){
ret[key] = Exits[key]["obv"];
}
return ret;
}
//Use this to hide an exit
int HideExit( string dir ) {
if ( !Exits[dir] ) return 0;
else return Exits[dir]["obv"] = 0;
}
//Use this to show a hidden exit
int ShowExit( string dir ) {
if ( !Exits[dir] ) return 0;
else return Exits[dir]["obv"] = 1;
}
/* /lib/obj/room.c
* From the Dead Souls LPC Library
* The room object used to represent any room in the game
* Created by Descartes of Borg 940711
* Version: @(#) room.c 1.20@(#)
* Last Modified: 050912
*
* Updated by Shadyman to support VERBOSE_EXITS
* And COLORIZED_EXITS on 1-Sep-2008
*/
#ifndef NM_STYLE_EXITS
#define NM_STYLE_EXITS 1
#endif
#ifndef COLORIZED_EXITS
#define COLORIZED_EXITS 1
#endif
#ifndef VERBOSE_EXITS
#define VERBOSE_EXITS 1
#endif
#include <lib.h>
#include <rooms.h>
#include <config.h>
#include <daemons.h>
#include <function.h>
#include <medium.h>
#include <message_class.h>
#include <talk_type.h>
#include <terrain_types.h>
#include <privs.h>
inherit LIB_SHADOW_HOOK;
inherit LIB_CLEAN;
inherit LIB_CONTAINER;
inherit LIB_EXITS;
inherit LIB_DESCRIPTION;
inherit LIB_INVENTORY;
inherit LIB_LOOK;
inherit LIB_PROPERTIES;
inherit LIB_AMBIANCE;
inherit LIB_READ;
inherit LIB_SAVE;
inherit LIB_MONEY;
private function Bury = 0;
private string Climate = "temperate";
private int DayLight = -1970;
private int counter = 0;
private static string DayLong = 0;
private object array DummyItems = ({});
private static int GasCheck = time();
private float Gravity = 1.0;
private static mixed Listen = 0;
private int NightLight = -1970;
private static string NightLong = 0;
private static int NoReplace = 0;
private static int PlayerKill = 0;
private static int PoisonGas = 0;
private static int ResetNumber = 0;
private static mixed Search = 0;
private static int Shade = 0;
private static mixed Smell = 0;
private static mixed Touch = 0;
private string Town = "wilderness";
private int DefaultExits = 1;
private int Flying = 1;
private int Sitting = 0;
private int Kneeling = 0;
private int Standing = 0;
private int Swimming = 0;
private int ObviousVisible = 1;
private int ActionChance = 10;
mapping ItemsMap = ([]);
private static mixed global_item;
private static mixed Action;
private int tick_resolution = 5;
private int TerrainType = T_OUTDOORS;
private int Medium = MEDIUM_LAND;
private mapping ActionsMap = ([]);
private string SinkRoom = "";
private string FlyRoom = "";
string GetClimate();
int GetNightLight();
int GetDayLight();
int GetShade();
mixed direct_delete_exit_str(){
return 1;
}
mixed indirect_delete_exit_str(){
return 1;
}
varargs int eventPrint(string msg, mixed arg2, mixed arg3);
/*********** /lib/room.c data manipulation functions **********/
void CheckActions(){
if(sizeof(ActionsMap)){
foreach(mixed key, mixed val in ActionsMap){
if( ActionChance > random(100) ){
if(functionp(key)) evaluate(key);
else eventPrint(key);
}
}
}
if( ActionChance > random(100) ){
int x;
if( functionp(Action) ) evaluate(Action);
else if( pointerp(Action) && (x = sizeof(Action)) ){
mixed act;
act = Action[random(x)];
if(functionp(act)){
evaluate(act);
return;
}
else eventPrint(act);
}
}
}
void heart_beat(){
counter++;
inventory::heart_beat();
if(counter > 9999) counter = 0;
CheckActions();
}
void SetAction(int chance, mixed val){
ActionChance = chance;
if( stringp(val) ) val = ({ val });
else if( !functionp(val) && !pointerp(val) )
error("Bad argument 2 to SetAction()\n");
Action = val;
}
mixed GetAction(){ return Action; }
mapping SetActionsMap(mapping ActMap){
if(ActMap && sizeof(ActMap)) ActionsMap = ActMap;
return copy(ActionsMap);
}
mapping GetActionsMap(){
return copy(ActionsMap);
}
int SetFrequency(int tick){
if(tick) tick_resolution = tick;
else tick_resolution = 5;
set_heart_beat(0);
return tick_resolution;
}
int GetFrequency(){
return tick_resolution;
}
int GetTerrainType(){
return TerrainType;
}
int SetTerrainType(int i){
if(i) TerrainType = i;
else return TerrainType;
}
int AddTerrainType(int i){
if(!bitshiftedp(i)) return 0;
else TerrainType = TerrainType | i;
return TerrainType;
}
int RemoveTerrainType(int i){
if(!bitshiftedp(i)) return 0;
else TerrainType = TerrainType ^ i;
return TerrainType;
}
int GetAmbientLight(){
int a, dayset, nightset;
dayset = this_object()->GetDayLight();
nightset = this_object()->GetNightLight();
if(dayset == -1970 && nightset == -1970 ){
a = ambiance::GetAmbientLight();
}
else if( query_night() && nightset != -1970 ){
a = nightset;
}
else if(!query_night() && dayset != -1970){
a = dayset;
}
else {
a = ambiance::GetAmbientLight();
}
if( GetClimate() != "indoors" ){
//a += SEASONS_D->GetRadiantLight() - GetShade();
}
foreach(object ob in all_inventory()){
a += ob->GetRadiantLight();
}
return a;
}
function GetBury(){
return Bury;
}
function SetBury(function what){
Bury = what;
}
static string GetExtraLong(){
int i;
string *l,*tmp;
string ret;
object array stuff;
ret = " ";
tmp = ({});
stuff=all_inventory(this_object());
for(i=0; i<sizeof(stuff);i++){
if(tmp = ({ stuff[i]->GetAffectLong() }) && !sizeof(l)) l = tmp;
if( !sizeof(l) ) return 0;
if(tmp = ({ stuff[i]->GetAffectLong() }) ) l += tmp;
}
if( !sizeof(l) ) return 0;
ret += implode(l, " ");
return ret;
}
string GetInternalDesc(){
string ret, tmp;
if( DayLong && !query_night() ){
ret = DayLong;
}
else if( NightLong && query_night() ){
ret = NightLong;
}
else {
ret = container::GetInternalDesc();
}
if( !ret ){
ret = "";
}
if( tmp = GetExtraLong() ){
ret += GetExtraLong();
}
return ret;
}
int GetResetNumber(){
return ResetNumber;
}
string array GetId(){ return ({}); }
string SetDayLong(string str){ return (DayLong = str); }
string GetDayLong(){ return DayLong; }
string SetNightLong(string str){ return (NightLong = str); }
string GetNightLong(){ return NightLong; }
string SetClimate(string str){
if(str == "indoors" && TerrainType == T_OUTDOORS) TerrainType = T_INDOORS;
return (Climate = str);
}
string GetClimate(){ return Climate; }
float SetGravity(float h){ return (Gravity = h); }
float GetGravity(){ return Gravity; }
int GetDayLight(){
return DayLight;
}
static int SetDayLight(int x){
return (DayLight = x);
}
object array GetDummyItems(){
DummyItems = ({});
foreach(object item in all_inventory(this_object())){
if(base_name(item) == LIB_DUMMY){
DummyItems += ({ item });
}
}
return DummyItems;
}
varargs void AddItem(mixed item, mixed val, mixed adjectives){
object ob, same_dummy;
object *dummies = filter(all_inventory(this_object()), (: base_name(LIB_DUMMY) :) );
global_item = item;
if( objectp(item) ){
same_dummy = filter(all_inventory(),(: base_name($1) == base_name(global_item) :));
if(sizeof(same_dummy)) return;
ob = item;
}
else {
if( stringp(item) ){
item = ({ item });
}
if( stringp(adjectives) ){
adjectives = ({ adjectives });
}
same_dummy = filter(dummies,(: member_array(global_item[0],$1->GetId()) != -1 :));
if(sizeof(same_dummy)) return;
ob = new(LIB_DUMMY, item, val, adjectives);
}
ob->eventMove(this_object());
DummyItems = ({ DummyItems..., ob });
}
mapping RemoveItem(mixed item){
if( objectp(item) ){
DummyItems -= ({ item });
item->eventDestruct();
return copy(Items);
}
else if( !arrayp(item) ){
item = ({ item });
}
foreach(object ob in GetDummyItems()){
if( sizeof(ob->GetId() & item) ){
ob->eventDestruct();
DummyItems -= ({ ob });
return copy(Items);
}
}
}
mapping SetItems(mixed items){
if(sizeof(DummyItems)) DummyItems->eventDestruct();
DummyItems = ({});
if( arrayp(items) ){
items->eventMove(this_object());
DummyItems = items;
}
else if( mapp(items) ){
ItemsMap = items;
foreach(mixed key, mixed val in items){
string array adjs = ({});
object ob;
if( objectp(key) ){
object *same_dummy = ({});
global_item = key;
same_dummy = filter(all_inventory() ,(: base_name($1) == base_name(global_item) :));
if(sizeof(same_dummy)) continue;
ob = key;
}
if( stringp(key) ){
key = ({ key });
}
else {
if( sizeof(key) == 2 && arrayp(key[0]) ){
adjs = key[1];
key = key[0];
}
}
ob = new(LIB_DUMMY, key, val, adjs);
ob->eventMove(this_object());
DummyItems = ({ DummyItems..., ob });
}
}
else {
error("Bad argument 1 to SetItems(), expected object array or "
"mapping.\n");
}
return copy(ItemsMap);
}
mapping GetItemsMap(){
return copy(ItemsMap);
}
mapping GetSmellMap(){
mapping Smells = ([]);
foreach(object ob in GetDummyItems()){
if( ob->GetSmell() ){
Smells[ob->GetId()] = ob->GetSmell();
}
}
if(this_object()->GetSmell()) Smells["default"] = this_object()->GetSmell();
return copy(Smells);
}
mapping GetListenMap(){
mapping Listens = ([]);
foreach(object ob in GetDummyItems()){
if( ob->GetListen() ){
Listens[ob->GetId()] = ob->GetListen();
}
}
if(this_object()->GetListen()) Listens["default"] = this_object()->GetListen();
return copy(Listens);
}
mapping QueryMap(string str){
switch(str){
case "SetItems" : return GetItemsMap();break;
case "SetSmell" : return GetSmellMap();break;
case "SetListen" : return GetListenMap();break;
case "SetInventory" : return this_object()->GetInventory();break;
default : return ([]);
}
}
varargs void AddListen(mixed item, mixed val){
if( !val ){
Listen = item;
return;
}
if( !item || item == "default" ){
Listen = val;
return;
}
if( stringp(item) ){
item = ({ item });
}
foreach(string tmp in item){
foreach(object ob in GetDummyItems()){
if( ob->id(tmp) ){
ob->SetListen(val);
break;
}
}
}
}
mixed GetListen(){
return Listen;
}
varargs void RemoveListen(mixed item){
if( !item || item == "default" ){
Listen = 0;
return;
}
foreach(object ob in GetDummyItems()){
if( stringp(item) ){
if( ob->id(item) ){
ob->SetListen(0);
}
}
else if( arrayp(item) ){
if( sizeof(ob->GetId() & item) ){
ob->SetListen(0);
}
}
}
}
varargs void SetListen(mixed items, mixed arg){
if( !mapp(items) ){
if( !arg ){
AddListen("default", items);
}
else {
AddListen(items, arg);
}
return;
}
foreach(mixed key, mixed val in items){
AddListen(key, val);
}
}
int SetMedium(int medium){
Medium = medium;
return Medium;
}
int GetMedium(){
return Medium;;
}
int GetNightLight(){
return NightLight;
}
int GetClimateExposed(){
string *nonexposed_media = ({ MEDIUM_SPACE, MEDIUM_WATER });
int nonexposed_terrain = (T_SEAFLOOR|T_INDOORS|T_UNDERWATER|T_UNDERGROUND|T_SPACE|T_PLANAR|T_BIOLOGICAL);
if(GetClimate()=="indoors") return 0;
if(GetTerrainType() & (nonexposed_terrain)) return 0;
if(member_array(GetMedium(), nonexposed_media) != -1) return 0;
return 1;
}
static int SetNightLight(int x){
return (NightLight = x);
}
int SetNoReplace(int x){ return (NoReplace = x); }
int GetNoReplace(){ return NoReplace; }
int GetPlayerKill(){
return PlayerKill;
}
int SetPlayerKill(int x){
return (PlayerKill = x);
}
int AddPoisonGas(int x){
PoisonGas += x;
return PoisonGas;
}
int GetPoisonGas(){
int x;
if( PoisonGas < 1 ){
return 0;
}
x = time() - GasCheck;
GasCheck = time();
if( x > 0 && x < 4 ){
x = 1;
}
else {
x = x/4;
}
PoisonGas -= x;
if( PoisonGas < 0 ){
PoisonGas = 0;
}
return PoisonGas;
}
int SetPoisonGas(int x){
return (PoisonGas = x);
}
void AddRead(mixed item, mixed val){
if( stringp(item) ){
item = ({ item });
}
foreach(string tmp in item){
foreach(object ob in GetDummyItems()){
if( ob->id(tmp) ){
ob->SetRead(val);
break;
}
}
}
}
void RemoveRead(mixed item){
foreach(object ob in GetDummyItems()){
if( stringp(item) ){
if( ob->id(item) ){
ob->SetRead(0);
}
}
else if( arrayp(item) ){
if( sizeof(ob->GetId() & item) ){
ob->SetRead(0);
}
}
}
}
varargs void SetRead(mixed items, mixed arg){
if( !mapp(items) ){
AddRead(items, arg);
return;
}
foreach(mixed key, mixed val in items){
AddRead(key, val);
}
}
int GetShade(){
return Shade;
}
static int SetShade(int x){
return (Shade = x);
}
varargs void AddSearch(mixed item, mixed val){
if( !val ){
Search = item;
return;
}
if( !item || item == "default" ){
Search = val;
return;
}
if( stringp(item) ){
item = ({ item });
}
foreach(string tmp in item){
foreach(object ob in GetDummyItems()){
if( ob->id(tmp) ){
ob->SetSearch(val);
break;
}
}
}
}
varargs mixed GetSearch(){
return Search;
}
varargs void RemoveSearch(mixed item){
if( !item || item == "default" ){
Search = 0;
return;
}
foreach(object ob in GetDummyItems()){
if( stringp(item) ){
if( ob->id(item) ){
ob->SetSearch(0);
}
}
else if( arrayp(item) ){
if( sizeof(ob->GetId() & item) ){
ob->SetSearch(0);
}
}
}
}
varargs void SetSearch(mixed items, mixed arg){
if( !mapp(items) ){
if( !arg ){
AddSearch("default", items);
}
else {
AddSearch(items, arg);
}
return;
}
foreach(mixed key, mixed val in items){
AddSearch(key, val);
}
}
varargs void AddSmell(mixed item, mixed val){
if( !val ){
Smell = item;
return;
}
if( !item || item == "default" ){
Smell = val;
return;
}
if( stringp(item) ){
item = ({ item });
}
foreach(string tmp in item){
foreach(object ob in GetDummyItems()){
if( ob->id(tmp) ){
ob->SetSmell(val);
break;
}
}
}
}
varargs mixed GetSmell(){
return Smell;
}
varargs void RemoveSmell(mixed item){
if( !item || item == "default" ){
Smell = 0;
return;
}
foreach(object ob in GetDummyItems()){
if( stringp(item) ){
if( ob->id(item) ){
ob->SetSmell(0);
}
}
else if( arrayp(item) ){
if( sizeof(ob->GetId() & item) ){
ob->SetSmell(0);
}
}
}
}
varargs void SetSmell(mixed items, mixed arg){
if( !mapp(items) ){
if( !arg ){
AddSmell("default", items);
}
else {
AddSmell(items, arg);
}
return;
}
foreach(mixed key, mixed val in items){
AddSmell(key, val);
}
}
varargs void AddTouch(mixed item, mixed val){
if( !val ){
Touch = item;
return;
}
if( !item || item == "default" ){
Touch = val;
return;
}
if( stringp(item) ){
item = ({ item });
}
foreach(string tmp in item){
foreach(object ob in GetDummyItems()){
if( ob->id(tmp) ){
ob->SetTouch(val);
break;
}
}
}
}
varargs void RemoveTouch(mixed item){
if( !item || item == "default" ){
Touch = 0;
return;
}
foreach(object ob in GetDummyItems()){
if( stringp(item) ){
if( ob->id(item) ){
ob->SetTouch(0);
}
}
else if( arrayp(item) ){
if( sizeof(ob->GetId() & item) ){
ob->SetTouch(0);
}
}
}
}
varargs void SetTouch(mixed items, mixed arg){
if( !mapp(items) ){
if( !arg ){
AddTouch("default", items);
}
else {
AddTouch(items, arg);
}
return;
}
foreach(mixed key, mixed val in items){
AddTouch(key, val);
}
}
string GetTown(){ return Town; }
string SetTown(string town){ return (Town = town); }
/** this stuff is for backwards compat **/
mixed SetProperty(string prop, mixed val){
if( prop == "light" ){
if( !val ) return val;
if( val < 0 ) return val;
else return ambiance::SetAmbientLight(val*25);
}
else if( prop == "night light" ){
if( !val ) return val;
if( val < 0 ) return val;
else return SetNightLight(15*val);
}
else return properties::SetProperty(prop, val);
}
mixed SetProperties(mapping mp){
if( mp["light"] ){
SetProperty("light", mp["light"]);
}
else if( mp["night light"] ){
SetProperty("night light", mp["night light"]);
}
return properties::SetProperties(mp);
}
string GetLong(){
return GetInternalDesc();
}
string SetLong(string str){
return SetInternalDesc(str);
}
int CanAttack( object attacker, object who ){
if( PlayerKill ){
return 1;
}
attacker->RemoveHostile( who );
return 0;
}
varargs int eventShow(object who, string args){
string str;
if( !(str = (string)SEASONS_D->GetLong(args)) ){
who->eventPrint("You do not see that there.");
return 1;
}
who->eventPrint(str);
eventPrint(who->GetName() + " looks at the " + args + ".", who);
}
/*********** /lib/room.c events ***********/
mixed eventBuryItem(object who, object tool, object what){
if( !functionp(Bury) ){
return "You cannot bury things here!";
}
if( functionp(Bury) & FP_OWNER_DESTED ){
return "You cannot bury things here.";
}
return evaluate(Bury, who, tool, what);
}
varargs mixed eventHearTalk(object who, object target, int cls, string verb,
string msg, string lang){
object *obs;
string exit, door;
switch(cls){
case TALK_PRIVATE:
return 1;
case TALK_SEMI_PRIVATE:
target->eventHearTalk(who, target, cls, verb, msg, lang);
eventPrint("%^BOLD%^CYAN%^" + (string)who->GetName() +
" whispers something to " + (string)target->GetName() + ".",
MSG_CONV, ({ who, target }));
return 1;
case TALK_LOCAL:
obs = get_livings(this_object(),1);
if(sizeof(obs)) obs -= ({ who });
if(sizeof(obs))
obs->eventHearTalk(who, target, cls, verb, msg, lang);
obs = get_livings(this_object(),2);
if(sizeof(obs)) obs -= ({ who });
if(sizeof(obs))
obs->eventHearTalk(who, target, cls, verb, msg, lang);
return 1;
case TALK_AREA:
foreach(exit in GetExits()){
string tmp;
tmp = GetExit(exit);
if( !find_object(tmp) ) continue;
//if( (door = GetDoor(exit)) && (int)door->GetClosed() ) continue;
tmp->eventHearTalk(who, target, TALK_LOCAL, verb, msg, lang);
}
foreach(exit in GetEnters(1)){
string tmp;
tmp = GetEnter(exit);
if( !find_object(tmp) ) continue;
if( (door = GetDoor(exit)) && (int)door->GetClosed() ) continue;
tmp->eventHearTalk(who, target, TALK_LOCAL, verb, msg, lang);
}
obs = filter(all_inventory(),
(: (int)$1->is_living() && $1 != $(who) :));
obs->eventHearTalk(who, target, cls, verb, msg, lang);
return 1;
}
}
int eventMove(){ return 0; }
varargs int eventPrint(string msg, mixed arg2, mixed arg3){
object *targs;
int msg_class;
targs = filter(all_inventory(), (: (int)$1->is_living() :));
if( !arg2 && !arg3 ){
msg_class = MSG_ENV;
}
else if( objectp(arg2) || arrayp(arg2) ){
if( objectp(arg2) ) arg2 = ({ arg2 });
foreach(mixed mount in arg2){
object *riders;
if(!mount) continue;
riders = mount->GetRiders();
if(riders) targs += riders;
}
targs -= arg2;
if( !arg3 ) msg_class = MSG_ENV;
else if(intp(arg3)) msg_class = arg3;
}
else if(!arg3){
if(intp(arg2)) msg_class = arg2;
else msg_class = MSG_ENV;
}
else if( objectp(arg3) || arrayp(arg3) ){
if( objectp(arg3) ) arg3 = ({ arg3 });
foreach(mixed mount in arg3){
object *riders;
if(!mount) continue;
riders = mount->GetRiders();
if(riders) targs += riders;
}
targs -= arg3;
msg_class = arg2;
}
targs->eventPrint(msg, msg_class);
return 1;
}
static void create(){
exits::create();
reset(query_reset_number());
set_heart_beat(0);
if( replaceable(this_object()) && !GetNoReplace() ){
string array tmp= inherit_list(this_object());
if( sizeof(tmp) == 1 ){
replace_program(tmp[0]);
}
}
}
int CanReceive(object ob){
if(!GetProperty("no teleport") || !living(ob)) return container::CanReceive(ob);
else {
string verb = query_verb();
string *allowed = ({ "go", "climb", "jump", "enter", "fly", "crawl" });
if(member_array(verb, allowed) == -1 && !archp(this_player())){
write("Your teleportation is prevented.");
return 0;
}
}
return container::CanReceive(ob);
}
varargs void reset(int count){
if(sizeof(all_inventory())){
foreach(object element in deep_inventory()){
if(element->GetNoClean()) return;
}
}
inventory::reset(count);
all_inventory()->reset(count);
ResetNumber++;
}
int id(){
return 0;
}
int inventory_accessible(){
return 1;
}
int inventory_visible(){
return 1;
}
int SetNoDefaultExits(int i){
if(!i) i = 0;
DefaultExits = bool_reverse(i);
ObviousVisible = DefaultExits;
return DefaultExits;
}
int SetDefaultExits(int i){
if(!i) i = 0;
DefaultExits = i;
ObviousVisible = DefaultExits;
return DefaultExits;
}
int SetCanFly(int i){
if(i && i > 0) Flying = 1;
else Flying = 0;
}
mixed CanFly(object who, string dest){
if(!who) who = this_player();
if(!dest) dest = "";
if(MEDIUM_WATER == Medium || MEDIUM_SPACE == Medium) return 0;
if(sizeof(FlyRoom)) return 1;
return Flying;
}
int SetCanSwim(int i){
if(i && i > 0) Swimming = 1;
else Swimming = 0;
}
mixed CanSwim(object who, string dest){
if(!who) who = this_player();
if(!dest) dest = "";
if((MEDIUM_WATER == Medium) || (MEDIUM_SURFACE == Medium) ) return 1;
if(GetTerrainType() & (T_ALL_SEA)) return 1;
return Swimming;
}
int SetCanStand(int i){
if(i && i > 0) Standing = 1;
else Standing = 0;
}
mixed CanStand(object who, string dest){
if(!who) who = this_player();
if(!dest) dest = "";
if(GetTerrainType() & (T_SPACE | T_UNDERWATER | T_SURFACE)) return 0;
if(GetTerrainType() & (T_SEAFLOOR)) return 1;
if((MEDIUM_AIR == Medium)) return 0;
if((MEDIUM_LAND == Medium)) return 1;
return Standing;
}
int SetCanSit(int i){
if(i && i > 0) Sitting = 1;
else Sitting = 0;
}
mixed CanSit(object who, string dest){
if(!who) who = this_player();
if(!dest) dest = "";
if(GetTerrainType() & (T_SPACE | T_UNDERWATER | T_SURFACE)) return 0;
if(GetTerrainType() & (T_SEAFLOOR)) return 1;
if((MEDIUM_AIR == Medium)) return 0;
if((MEDIUM_LAND == Medium)) return 1;
return Sitting;
}
int SetCanKneel(int i){
if(i && i > 0) Kneeling = 1;
else Kneeling = 0;
}
mixed CanKneel(object who, string dest){
if(!who) who = this_player();
if(!dest) dest = "";
if(GetTerrainType() & (T_SPACE | T_UNDERWATER | T_SURFACE)) return 0;
if(GetTerrainType() & (T_SEAFLOOR)) return 1;
if((MEDIUM_AIR == Medium)) return 0;
if((MEDIUM_LAND == Medium)) return 1;
return Kneeling;
}
int SetNoObviousExits(int i){
if(!i) i = 0;
ObviousVisible = bool_reverse(i);
DefaultExits = ObviousVisible;
return ObviousVisible;
}
int GenerateObviousExits(){
string *normals;
string *exits;
string dir_string, enters;
mapping obv;
//exits = GetExits();
obv = GetObvMap();
exits = filter(GetExits(), (: !($1 == "up" && !(this_object()->GetVirtualSky()) &&
load_object(GetExit($1))->GetVirtualSky()) :) );
enters = "";
normals = ({ "north", "south", "east", "west", "up", "down" });
normals += ({ "northeast", "southeast", "northwest", "southwest" });
normals += ({ "out" });
dir_string = "";
if(sizeof(GetEnters(1)-({0}))){
foreach(string enter in this_object()->GetEnters(1)){
enters += "enter "+enter;
if(member_array(enter,this_object()->GetEnters(1)) !=
sizeof(this_object()->GetEnters(1)) -1){
enters +=", ";
}
}
}
if(NM_STYLE_EXITS){
if(member_array("north",exits) != -1 && obv["north"] == 1) dir_string += "n, ";
if(member_array("south",exits) != -1 && obv["south"] == 1) dir_string += "s, ";
if(member_array("east",exits) != -1 && obv["east"] == 1) dir_string += "e, ";
if(member_array("west",exits) != -1 && obv["west"] == 1) dir_string += "w, ";
if(member_array("northeast",exits) != -1 && obv["northeast"] == 1) dir_string += "ne, ";
if(member_array("northwest",exits) != -1 && obv["northwest"] == 1) dir_string += "nw, ";
if(member_array("southeast",exits) != -1 && obv["southeast"] == 1) dir_string += "se, ";
if(member_array("southwest",exits) != -1 && obv["southwest"] == 1) dir_string += "sw, ";
if(member_array("up",exits) != -1 && obv["up"] == 1) dir_string += "u, ";
if(member_array("down",exits) != -1 && obv["down"] == 1) dir_string += "d, ";
if(member_array("out",exits) != -1 && obv["out"] == 1) dir_string += "out, ";
}
else dir_string = implode(keys(obv),", ")+", ";
if(sizeof(this_object()->GetEnters(1) - ({0}) )){
if(sizeof(this_object()->GetExits())) dir_string += ", ";
dir_string += enters;
}
if(last(dir_string,2) == ", ") dir_string = truncate(dir_string,2);
dir_string = replace_string(dir_string,", , ",", ");
if(ObviousVisible) SetObviousExits(dir_string);
return 1;
}
int eventReceiveObject(object ob){
return container::eventReceiveObject(ob);
}
string SetFlyRoom(string str){
FlyRoom = str;
return FlyRoom;
}
string GetFlyRoom(){
return FlyRoom;
}
string SetSinkRoom(string str){
SinkRoom = str;
return SinkRoom;
}
string GetSinkRoom(){
return SinkRoom;
}
string GenerateVerboseExits(){
string *normals;
int exitCount = 0;
string *roomexits;
string *entersArray;
string dir_string, enters, door;
string temp,temp2;
mapping obv;
roomexits = GetExits();
obv = GetObvMap();
//Quick hack, may be a better way than this.
foreach (string ex in roomexits ) {
if (obv[ex] == 0) roomexits -= ({ex});
}
enters = "";
normals = ({ "north", "south", "east", "west", "up", "down" });
normals += ({ "northeast", "southeast", "northwest", "southwest" });
normals += ({ "out" });
dir_string = "";
if( sizeof(GetEnters(1)-({0})))
{
entersArray = this_object()->GetEnters(1);
foreach( string en in entersArray )
{
entersArray[exitCount++] = "enter "+entersArray[exitCount];
}
roomexits += entersArray;
}
//Quick hack, may be a better way than this.
foreach (string ex in roomexits ) {
if (obv[ex] == 0) roomexits -= ({ex});
}
exitCount = 0;
if (COLORIZED_EXITS) {
if( sizeof( roomexits ) == 0 )
dir_string += "%^BOLD%^WHITE%^There are no obvious exits%^RESET%^";
else if( sizeof(roomexits) == 1 )
dir_string += "%^BOLD%^WHITE%^There is "+ cardinal((int)sizeof(roomexits)) +" obvious exit%^RESET%^: ";
else
dir_string += "%^BOLD%^WHITE%^There are "+ cardinal((int)sizeof(roomexits)) +" obvious exits%^RESET%^: ";
} else {
if( sizeof( roomexits ) == 0 )
dir_string += "There are no obvious exits";
else if( sizeof(roomexits) == 1 )
dir_string += "There is "+ cardinal((int)sizeof(roomexits)) +" obvious exit: ";
else
dir_string += "There are "+ cardinal((int)sizeof(roomexits)) +" obvious exits: ";
}
foreach( string ex in roomexits )
{
if (COLORIZED_EXITS) {
//Generate Colorized Verbose list
if ( door = GetDoor(ex) ) {
temp = door->GetClosed();
temp2 = door->GetDesc();
if (temp) dir_string += "a closed "+temp2+" %^RED%^"+roomexits[exitCount]+"%^RESET%^";
else dir_string += "an open "+temp2+" %^BOLD%^GREEN%^"+roomexits[exitCount]+"%^RESET%^";
} else dir_string += "%^BOLD%^GREEN%^"+roomexits[exitCount]+"%^RESET%^";
} else {
//Generate non-colorized Verbose list
if ( door = GetDoor(ex) ) {
temp = door->GetClosed();
temp2 = door->GetDesc();
if (temp) dir_string += "a closed "+temp2+" "+roomexits[exitCount];
else dir_string += "an open "+temp2+" "+roomexits[exitCount];
} else dir_string += roomexits[exitCount];
}
if( ++exitCount == (sizeof( roomexits )-1) ) dir_string += ", and ";
else dir_string += ", ";
}
if (last(dir_string,2) == ", ") dir_string = truncate(dir_string,2);
dir_string = replace_string(dir_string,", , ",", ") + ".";
return dir_string;
}
static void init(){
if(this_object()->GetProperty("indoors")) SetClimate("indoors");
if(!sizeof(GetObviousExits()) && DefaultExits > 0 && ObviousVisible) GenerateObviousExits();
if((Action && sizeof(Action)) || sizeof(ActionsMap)) set_heart_beat(tick_resolution);
}
//UNTOUCHED CODE:
switch( i ){
case VISION_BLIND:
this_object()->eventPrint("You are blind and can see nothing.");
break;
case VISION_TOO_DARK:
this_object()->eventPrint("It is much too dark to see.");
break;
case VISION_DARK:
this_object()->eventPrint("It is too dark to see.");
break;
case VISION_TOO_BRIGHT:
this_object()->eventPrint("It is much too %^YELLOW%^bright%^RESET%^ to see.");
break;
case VISION_BRIGHT:
this_object()->eventPrint("It is too %^YELLOW%^bright%^RESET%^ to see.");
break;
}
//CHANGED CODE:
if( !brief ){
if( i == VISION_CLEAR ){
desc = (string)env->GetObviousExits() || "";
if(desc && desc != "")
desc = capitalize((string)env->GetShort() || "")
+ " [" + desc + "]\n";
else desc = capitalize((string)env->GetShort()+"\n" || "\n");
if(!NM_STYLE_EXITS){
desc = capitalize((string)env->GetShort()+"\n" || "\n");
if (VERBOSE_EXITS) {
altern_obvious = env->GenerateVerboseExits();
} else {
altern_obvious = "Obvious exit$Q: "+(string)env->GetObviousExits() || "none";
}
}
}
else desc = "\n";
//UNTOUCHED CODE:
if( i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM ){
if(this_object()->GetProperty("automapping")) desc += simple_map(env)+"\n";
desc += (string)env->GetLong();
}
if(functionp(tmp = (mixed)env->GetSmell("default")))
tmp = (string)(*tmp)("default");
smell = tmp;
if(functionp(tmp = (mixed)env->GetListen("default")))
tmp = (string)(*tmp)("default");
sound = tmp;
if( functionp(tmp = (mixed)env->GetTouch("default")) )
tmp = evaluate(tmp, "default");
touch = tmp;
}
else {
if(i == VISION_CLEAR || i == VISION_LIGHT || i == VISION_DIM){
desc = (string)env->GetShort();
if(this_object()->GetProperty("automapping")) desc += simple_map(env)+"\n";
if(NM_STYLE_EXITS){
if( (tmp = (string)env->GetObviousExits()) && tmp != "" )
desc += " [" + tmp + "]";
else desc += "\n";
}
else altern_obvious = "Obvious exits: "+(string)env->GetObviousExits() || "none";
}
else desc = "\n";
}
if( desc ) this_object()->eventPrint(desc, MSG_ROOMDESC);
if(sizeof(altern_obvious)){
int quant = sizeof(env->GetExits()) + sizeof(env->GetEnters());
if(quant > 1) altern_obvious = replace_string(altern_obvious,"$Q","s");
else altern_obvious = replace_string(altern_obvious,"$Q","");
this_object()->eventPrint(altern_obvious,MSG_ROOMDESC);
}
if( smell ) this_object()->eventPrint("%^GREEN%^" + smell, MSG_ROOMDESC);
if( sound ) this_object()->eventPrint("%^CYAN%^" + sound, MSG_ROOMDESC);
if( touch ) this_object()->eventPrint("%^YELLOW%^" + touch, MSG_ROOMDESC);
#define CMD_NUM 1
somefun() {
int sock; //To hold the socket that the external_start will assign
string args; //To put the command arguments we want to send
...
//I have no idea what kind of args SVN takes.
args = "--some --svn --arguments";
sock = external_start( CMD_NUM, args, "read_call_back", "write_call_back", "close_call_back" );
if ( sock < 0 ) { //FAIL
//Error handling stuff here
return;
}
//Optional: Now you can send stuff like filling in a prompt or something similar
return socket_write(sock, "ls\n");
...
}
void read_call_back(int fd, mixed msg) {
//This is your meat and potatoes. Anything that gets echoed back from the external command gets sent here.
if (stringp(msg)) {
//Do some stuff
...
} else {
return;
}
}
void write_call_back( int sock ) {
//Shouldn't care much about this.
}
void close_call_back( int sock ) {
//Your socket a-splode!
//Do cleanup-stuff here if needed
}
ehm, there's code in edit_source.c to look up the right one which adds the proper define to configure.h, if yours is missing, add a test please!
/* /secure/daemon/SQL.c
* Author: Shadyman@QS, using code, comments, and some
* examples from FluffOS DB Package
* Date: 18-Aug-2008
* Redistribute as needed, but please leave headers intact
*
* This file acts as an intermediary between the lib and
* the driver's DB package to make things a little easier
* to use/more foolproof/implementable with less code.
*/
#include <db.h>
inherit LIB_DAEMON;
/* varargs int SQL_CONNECT (string server, string db,
* string username)
* Connects to the specified server and database, with
* the given username, or uses defaults if none given.
* All arguments are optional. Defaults from db.h
* Returns the connection handle (int >= 1). 0 is FAIL.
*/
varargs int sql_connect (string server, string db, string username) {
mixed foo;
if (!server || server == "") server = CONFIG_DB_HOST;
if (!db || db == "") db = CONFIG_DB;
if (!username || username == "") username = CONFIG_DB_USER;
foo = db_connect(server, db, username);
if (!intp(foo)) {
log_file(SQL_LOG,"db_connect returned: "+foo);
return 0;
} else {
return foo;
}
}
/* mixed SQL_QUERY (int handle, string query)
* Returns 0 on fail, ({}) on 0 rows, string for error message
* Returns array of arrays for resultset:
* ({ / * sizeof() == 105 * /
* ({ / * sizeof() == 7 * /
* 1,
* "dirk",
* "Dirk the Tired",
* "/domains/town/npc/dirk",
* "male",
* "0",
* "human"
* }),
* ...
* })
*/
mixed sql_query (int handle, string query) {
string *res = ({});
string *ret = ({});
mixed rows;
int i;
if (handle < 1) {
log_file(SQL_LOG,"Handle < 1... Not properly connected to DB");
return 0;
}
rows = db_exec(handle, query);
if( !rows ) {
return ({});
} else if( stringp(rows) ) { //Error out
log_file(SQL_LOG,rows);
return rows;
} else {
for(i=1; i<=rows; i++) {
res = db_fetch(handle, i);
ret += ({ res });
}
return ret;
}
}
/* Not yet implemented (maybe?) at the driver level.
*
* Commits the last set of transactions to the database
* NOTE: MSQL does not have transaction logic, but MySQL DOES,
* so you CAN allow commits if you disable
* the AUTOCOMMIT (SET AUTOCOMMIT=0) feature.
* See http://dev.mysql.com/doc/refman/5.0/en/commit.html for more.
* Saving a "commit" until after you spam commands keeps
* the unnecessary disk writes to a minimum, and you can
* "Undo" with a rollback if something goes wrong.
*
* Returns 1 on success, 0 on failure
*/
int sql_commit(int handle) {
return db_commit(handle);
}
/* Rolls back all db_exec() calls back to the last db_commit() call
* for the named connection handle.
* NOTE: MSQL does not support rollbacks, but MySQL CAN, if you
* disable the AUTOCOMMIT (SET AUTOCOMMIT=0);
* See http://dev.mysql.com/doc/refman/5.0/en/commit.html for more.
*
* Returns 1 on success, 0 on failure
*/
int sql_rollback(int handle) {
return db_rollback(handle);
}
/*
* Returns a string describing the database package's current status
* May be "" if nothing connected, or like "MYSQL->1" for MYSQL
* operating on handle 1.
*/
string sql_status() {
return db_status();
}
/*
* Closes the database named by 'handle'.
*/
int sql_close(int handle) {
return db_close(handle);
}
/* varargs mixed SQL_QUICKQUERY (string query, string server,
* string db, string username)
*
* A quick, clean-code way to insert, update or delete a
* record or recordset, since insert/update/delete queries
* have no resultset.
*
* Returns 1 on Success or 0 on Failure
*
* sql_quickquery can process multiple inserts/updates/deletes
* by making the "query" an array of queries. IE:
* ({ "INSERT INTO FOO WHERE..", "DELETE FROM BLAH WHERE.." })
* however, string queries will work also. IE:
* "INSERT INTO FOO WHERE..."
*/
varargs mixed sql_quickquery (mixed query, string server,
string db, string username) {
mixed handle;
int ret,i;
// if (!server || server == "") server = CONFIG_DB_HOST;
// if (!db || db == "") db = CONFIG_DB;
// if (!username || username == "") username = CONFIG_DB_USER;
handle = sql_connect(server, db, username); //Connect
if ( !intp(handle) || handle < 1 )
return 0;
if ( arrayp(query) ) {
for(i=0; i<=sizeof(query)-1; i++) {
//ret should normally be 0 or ({}) for no-return queries
ret = db_exec(handle, query[i]);
if ( ret != 0 && ret != ({}) ) {
//Log funny results.
log_file(SQL_LOG,"Query '"+query[i]+" returned something "
"funny: "+sprintf("%O",ret));
//Rollback all queries. (Maybe)
//sql_rollback(handle);
//FAIL. (Maybe)
return 0;
}
}
} else if ( stringp(query) ) {
ret = db_exec(handle, query);
} else { //WTF?
sql_close(handle); //Disconnect
return 0;
}
sql_commit(handle); //Not yet implemented
sql_close(handle); //Disconnect
}
#ifndef DB_H
#define DB_H
/**
* Set up Database Log
*/
#define SQL_LOG "/log/sql"
/**
* Set up Database Access
*/
//Default database name
#define CONFIG_DB "mud"
//General database user (least priviledges)
#define CONFIG_DB_USER "mud"
//General database user's password. General database user probably doesn't need a password.
#define CONFIG_DB_PASS ""
/**
* Set up Database Connection
*/
//If your sql server is on another machine, enter its IP here.
#define CONFIG_DB_HOST "127.0.0.1"
#endif /* DB_H */
|| check_include("INCL_MYSQL_MYSQL_H", "/usr/include/mysql/mysql.h"))) {
Change /usr/include/mysql/mysql.h as necessary #define PACKAGE_DB //Enable/disable the Database package
#ifdef PACKAGE_DB
#define USE_MYSQL 2 //Newfangled, working, MySQL code
#define DEFAULT_DB USE_MYSQL //Use MySQL code as opposed to MSQL, etc
/* Define whichever of the following gives your proper mysql.h location: Only define one, though.
* The rest aren't needed, so it's safe to comment them out.
* /
//#define INCL_LOCAL_MYSQL_H // "/usr/local/include/mysql.h"
//#define INCL_LOCAL_INCLUDE_MYSQL_MYSQL_H // "/usr/local/include/mysql/mysql.h
//#define INCL_LOCAL_MYSQL_MYSQL_H // "/usr/local/mysql/include/mysql.h"
#define INCL_MYSQL_MYSQL_H // "/usr/include/mysql/mysql.h"
//Change this to the location of your mysql.sock (or mysqld.sock, if you don't have a mysql.sock)
#define MYSQL_SOCKET_ADDRESS "/tmp/mysql.sock"
#endif
|| check_include("INCL_MYSQL_MYSQL_H", "/usr/include/mysql/mysql.h"))) {
Change /usr/include/mysql/mysql.h as necessary (Optional: Or... Find out which one yours is, there's a bunch of incl_mysql_'s in there, and #define it in the next step instead of INCL_MYSQL_MYSQL_H)#define PACKAGE_DB
#ifdef PACKAGE_DB
#define USE_MYSQL 2
#define DEFAULT_DB USE_MYSQL
#define INCL_MYSQL_MYSQL_H
#define MYSQL_SOCKET_ADDRESS "/tmp/mysql.sock"
#endif
Index: db.c
===================================================================
RCS file: /home/cvsroot/fluffos/packages/db.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 db.c
--- db.c 19 Jul 2008 22:11:24 -0000 1.1.1.1
+++ db.c 18 Aug 2008 19:14:11 -0000
@@ -144,7 +144,7 @@
{
int ret = 0;
db_t *db;
-
+
valid_database("close", &the_null_array);
db = find_db_conn(sp->u.number);
@@ -648,9 +648,9 @@
case FIELD_TYPE_VAR_STRING:
if (field->flags & BINARY_FLAG) {
#ifndef NO_BUFFER_TYPE
- v->item[i].type = T_BUFFER;
- v->item[i].u.buf = allocate_buffer(field->length);
- write_buffer(v->item[i].u.buf, 0, target_row[i], field->length);
+ v->item[i].type = T_BUFFER;
+ v->item[i].u.buf = allocate_buffer(field->max_length);
+ write_buffer(v->item[i].u.buf, 0, target_row[i], field->max_length);
#else
v->item[i] = const0u;
#endif
@@ -679,13 +679,14 @@
static int MySQL_connect (dbconn_t * c, const char * host, const char * database, const char * username, const char * password)
{
- int ret;
- MYSQL *tmp;
-
- tmp = ALLOCATE(MYSQL, TAG_DB, "MySQL_connect");
- *(c->mysql.errormsg) = 0;
+ int ret;
+ MYSQL *tmp;
+ tmp = ALLOCATE(MYSQL, TAG_DB, "MySQL_connect");
+ tmp = mysql_init(tmp);
+ *(c->mysql.errormsg) = 0;
- c->mysql.handle = mysql_connect(tmp, host, username, password);
+ c->mysql.handle = mysql_real_connect(tmp, host, username, password, database, 0, MYSQL_SOCKET_ADDRESS, 0);
+ //c->mysql.handle = mysql_connect(tmp, host, username, password);
if (!c->mysql.handle) {
strncpy(c->mysql.errormsg, mysql_error(tmp), sizeof(c->mysql.errormsg));
c->mysql.errormsg[sizeof(c->mysql.errormsg) - 1] = 0;