Esempio n. 1
0
void Streamable::doPrint(const bstring& toPrint) {
    const Player* player = dynamic_cast<Player*>(this);
    const Monster* monster = dynamic_cast<Monster*>(this);
    const Player* master = nullptr;
    Socket* sock = nullptr;

    if(player)
        sock = player->getSock();

    if(monster) {
        master = monster->getConstPlayerMaster();
        if(master)
            sock = master->getSock();
    }
    if(sock) {
        if(master) {
            if(!petPrinted) {
                sock->bprint("Pet> ");
                if(toPrint.find("\n") == bstring::npos)
                    petPrinted = true;
            }
            else {
                if(toPrint.find("\n") != bstring::npos)
                    petPrinted = false;
            }
        }
        if(streamColor)
            sock->bprintColor(toPrint);
        else
            sock->bprintNoColor(toPrint);
    }

}
Esempio n. 2
0
#define ATAPI_STAT_BSY	   0x80
#define ATAPI_STAT_DRDY    0x40
#define ATAPI_STAT_DMARDDF 0x20
#define ATAPI_STAT_SERVDSC 0x10
#define ATAPI_STAT_DRQ     0x08
#define ATAPI_STAT_CORR    0x04
#define ATAPI_STAT_CHECK   0x01

#define ATAPI_INTREASON_COMMAND 0x01
#define ATAPI_INTREASON_IO      0x02
#define ATAPI_INTREASON_RELEASE 0x04

#define ATAPI_REG_DATA		0
#define ATAPI_REG_FEATURES	1
#define ATAPI_REG_INTREASON	2
#define ATAPI_REG_SAMTAG	3
#define ATAPI_REG_COUNTLOW	4
#define ATAPI_REG_COUNTHIGH	5
#define ATAPI_REG_DRIVESEL	6
#define ATAPI_REG_CMDSTATUS	7
#define ATAPI_REG_ERROR		16	// read-only ERROR (write is FEATURES)

#define ATAPI_REG_MAX 24
Esempio n. 3
0
bstring splitPath(bstring & path, bstring const & filePath) {
	size_t i = filePath.find_last_of('/');
	if (i == (size_t)-1) {
		path = TEXT("/");
		return filePath;
	}
	++i;
	path = filePath.substr(0, i);
	return filePath.substr(i);
}
Esempio n. 4
0
bstring stripColor(bstring color) {
    std::ostringstream str;
    unsigned int i=0, max = color.getLength();
    for(; i < max ; i++) {
        if(color.getAt(i) == '^')
            i++;
        else
            str << color.getAt(i);
    }
    return(str.str());
}
Esempio n. 5
0
//---------------------------------------------------------------------
// put a local file --> remote 
bool Server::cmdPut(bstring const & localName, bstring const & remotePath, bool exists)
{
	DBGPRINT(("put '%s' '%s' %b\r\n", localName.c_str(), remotePath.c_str(), exists));
	bstring cmd = bstring(exists ? TEXT("reput \"") : TEXT("put \"")) + localName + TEXT("\" \"") + remotePath + TEXT("\"");

	if (!doCommand(cmd))
		return false;

	FILETIME ft;
	HANDLE hFile = CreateFile(localName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile == (HANDLE)HFILE_ERROR)
		return true; // copy succeeded

	GetFileTime(hFile, 0, 0, &ft);
	long fsHigh = 0;
	long fsLow = SetFilePointer(hFile, 0, &fsHigh, FILE_END);

	CloseHandle(hFile);

	bstring chmod = TEXT("----");
	if (defChMod.length() > 0 || exeChMod.length() > 0) {
		chmod = defChMod;
		size_t ldot = remotePath.find_last_of('.');
		if (ldot != (size_t)-1) {
			bstring x = remotePath.substr(ldot);
			std::map<bstring, bstring>::iterator i = exeExtensions.find(x);
			if (i != exeExtensions.end())
				chmod = exeChMod;
		}
		if (chmod.length() > 0) {
			cmd = bstring(TEXT("chmod ")) + chmod + TEXT(" \"") + remotePath + TEXT("\"");
			doCommand(cmd);
		}
	}

	// fake update the directory
	insertFile(remotePath, &ft, fsLow, fsHigh, '-', chmod);

	// we cannot set the file time
	if (disableMtime)
		return true;

	// if setting the mtime failes, do not try it again
	if (!this->cmdMtime(remotePath, &ft))
		disableMtime = true;

	// put already succeeded.
	return true;
}
Esempio n. 6
0
bool doTransferAscii(bstring const & filename) {
	WLock wlock;
	if (transferAscii)
		return true;
	if (modeExtensions.size() == 0)
		return false;
	// check the extension
	size_t dot = filename.find_last_of('.');
	if (dot == (size_t)-1)
		return false;

	bstring ext = filename.substr(dot);
	std::map<bstring, bstring>::iterator i = modeExtensions.find(ext);
	return i != modeExtensions.end();
}
Esempio n. 7
0
 void Action::identifier ( const bstring& value )
 {
     const com::Result result = ptr()->put_Id(value.value());
     if ( result.bad() ) {
         UNCHECKED_COM_ERROR(IAction,put_Id,result);
     }
 }
Esempio n. 8
0
//---------------------------------------------------------------------
// execute a SFTP command
bool Server::doCommand(bstring const & command, bstring & response) {
	Guard guard(this);
	if (!guard.isConnected()) return false;

	gLogProc(gPluginNumber, MSGTYPE_DETAILS, command.c_str());

	bchar buffer[8192];
	*buffer = 0;
	int r = guard.mapper->doSftp(command.c_str(), buffer);

	if (*buffer) {
		response = buffer;
		gLogProc(gPluginNumber, MSGTYPE_OPERATIONCOMPLETE, buffer);
	}
	return 0 != r;
}
Esempio n. 9
0
//---------------------------------------------------------------------
// add a file to the dir content - if not already there
void Server::insertFile(bstring const & remotePath, FILETIME * ft, unsigned long szLo, unsigned long szHi, char kind, bstring const & chmod) {
	bstring path, file;
	file = splitPath(path, remotePath);
	DirCache::iterator i = dirCache.find(path);
	if (i == dirCache.end())
		return;

	my_fxp_names * dir = i->second;	

	int count = dir->nnames;
	for (int i = 0; i < count; ++i) {
		fxp_name * fn = dir->names[i];
		if (file == fn->filename) {
			// already there
			return;
		}
	}
	// create a new structure and fill it
	my_fxp_names * ndir = (my_fxp_names *) malloc(sizeof(my_fxp_names));
	ndir->names = (fxp_name **)malloc(sizeof(fxp_name*) * (count + 1));
	
	fxp_name * n = ndir->names[0] = (fxp_name *)malloc(sizeof(fxp_name));
	RtlZeroMemory(n, sizeof(fxp_name));

	FILETIME ft2;
	SYSTEMTIME st;
	if (ft) {
		FileTimeToSystemTime(ft, &st);
	} else {
		GetSystemTime(&st);
		SystemTimeToFileTime(&st, &ft2);
		ft = &ft2;
	}

	char buffer[32];
	sprintf(buffer, "%d ", szLo);
#ifdef UNICODE
	char * chmod2;
	BCONVERT(char, 32, chmod2, chmod.c_str());
	char * file2;
	BCONVERT(char, 256, file2, file.c_str());
	std::string ln = kind + chmod2 + std::string(" 1 ? ? ") + buffer + " Jan  1 1990 " + file2; 
#else
	std::string ln = kind + chmod + std::string(" 1 ? ? ") + buffer + " Jan  1 1990 " + file; 
#endif
	n->longname = strdup(ln.c_str());
	n->filename = bstrdup(file.c_str());

	n->attrs.size.hi = szHi;
	n->attrs.size.lo = szLo;	
	n->attrs.mtime = FileTimeToUnixTime(ft);

	for (int i = 0; i < count; ++i) {
		ndir->names[i + 1] = dir->names[i];
	}
	ndir->nnames = count + 1;
	
	i->second = ndir;
}
Esempio n. 10
0
//---------------------------------------------------------------------
// get a remote file -> local
bool Server::cmdGet(bstring const & remotePath, bstring const & localName, bool exists)
{
	DBGPRINT(("get '%s' '%s' %b\r\n", remotePath.c_str(), localName.c_str(), exists));
	bstring cmd = bstring(exists ? TEXT("reget \"") : TEXT("get \"")) + remotePath + TEXT("\" \"") + localName + TEXT("\"");

	if (!doCommand(cmd))
		return false;

	FILETIME ft;
	fxp_attrs * attr = currentMapper->getLastAttr();
	if (UnixTimeToFileTime(attr->mtime, &ft)) {
		HANDLE hf = CreateFile(localName.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
		SetFileTime(hf, &ft, &ft, &ft);
		CloseHandle(hf);
	}
	return true;
}
Esempio n. 11
0
bstring effectSpellName(bstring effect) {
    effect = stripColor(effect.toLower());

    if(effect == "silent!") return("silence");
    if(effect == "blessed") return("bless");
    if(effect == "detect-invisible") return("detect-invisibility");
    if(effect == "invisible") return("invisibility");

    return(effect);
}
Esempio n. 12
0
char nameToColorCode(bstring name) {
    name = name.toLower();
    if(name == "blink")
        return('!');
    if(name == "blue")
        return('b');
    if(name == "bold blue")
        return('B');
    if(name == "red")
        return('r');
    if(name == "bold red")
        return('R');
    if(name == "cyan")
        return('c');
    if(name == "bold cyan")
        return('C');
    if(name == "green")
        return('g');
    if(name == "bold green")
        return('G');
    if(name == "magenta")
        return('m');
    if(name == "bold magenta")
        return('M');
    if(name == "yellow")
        return('y');
    if(name == "bold yellow")
        return('Y');
    if(name == "white")
        return('w');
    if(name == "bold white")
        return('W');
    if(name == "black")
        return('d');
    if(name == "grey")
        return('D');
    if(name == "gold")
        return('l');
    if(name == "cerulean")
        return('e');
    if(name == "pink")
        return('p');
    if(name == "sky blue")
        return('s');
    if(name == "brown")
        return('o');
    return('x');
}
Esempio n. 13
0
//---------------------------------------------------------------------
// update the file attributes
void Server::updateFileAttr(bstring const & path, bstring const & file, bstring const & attrs)
{
	DirCache::iterator i = dirCache.find(path);
	if (i == dirCache.end())
		return;

	my_fxp_names * dir = i->second;	
	int count = dir->nnames;
	for (int i = 0; i < count; ++i) {
		fxp_name * fn = dir->names[i];
		if (file == fn->filename) {
			// got it
			fn->attrs.permissions = bstrtol(attrs.c_str(), '\0', 8);
			return;
		}
	}
}
Esempio n. 14
0
bool Creature::hasCharm(bstring charmed) {
    etag    *cp=0;

    if(charmed == "")
        return(false);

    Player* player = getAsPlayer();

    if(!player)
        return(false);

    cp = player->first_charm;

    while(cp) {
        if(!strcmp(cp->enemy, charmed.c_str()))
            return(true);
        cp = cp->next_tag;
    }

    return(false);
}
Esempio n. 15
0
				atapi_xfermod = 0;
			}

//          printf( "atapi_r: atapi_xferlen=%d\n", atapi_xferlen );
			if( atapi_xferlen != 0 )
			{
				atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
				gdrom_alt_status = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
				atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
			}
			else
			{
				//mame_printf_debug("ATAPI: dropping DRQ\n");
				atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
				gdrom_alt_status = 0;
				atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
			}

			atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff;
			atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff;

			gdrom_raise_irq(machine);
		}

		if( atapi_data_ptr < atapi_data_len )
		{
			data = atapi_data[atapi_data_ptr++];
			data |= ( atapi_data[atapi_data_ptr++] << 8 );
			if( atapi_data_ptr >= atapi_data_len )
			{
//              printf( "atapi_r: read all bytes\n" );
				atapi_data_ptr = 0;
				atapi_data_len = 0;

				if( atapi_xferlen == 0 )
				{
					atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
					gdrom_alt_status = 0;
					atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
					gdrom_raise_irq(machine);
				}
			}
		}
		else
		{
			data = 0;
		}
	}
	else
	{
		reg = offset;

		// get read-only side of read-only/write-only registers from elsewhere
		if (reg == ATAPI_REG_FEATURES)
		{
			reg = ATAPI_REG_ERROR;
		}
		data = atapi_regs[reg];

		#if 0
		switch( reg )
		{
		case ATAPI_REG_DATA:
			printf( "atapi_r: data=%02x\n", data );
			break;
		case ATAPI_REG_ERROR:
			printf( "atapi_r: error=%02x\n", data );
			break;
		case ATAPI_REG_INTREASON:
			printf( "atapi_r: intreason=%02x\n", data );
			break;
		case ATAPI_REG_SAMTAG:
			printf( "atapi_r: samtag=%02x\n", data );
			break;
		case ATAPI_REG_COUNTLOW:
			printf( "atapi_r: countlow=%02x\n", data );
			break;
		case ATAPI_REG_COUNTHIGH:
			printf( "atapi_r: counthigh=%02x\n", data );
			break;
		case ATAPI_REG_DRIVESEL:
			printf( "atapi_r: drivesel=%02x\n", data );
			break;
		case ATAPI_REG_CMDSTATUS:
			printf( "atapi_r: cmdstatus=%02x\n", data );
			break;
		}
		#endif

		mame_printf_debug("ATAPI: read reg %d = %x (PC=%x)\n", reg, data, space.device().safe_pc());
	}

//  printf( "atapi_r( %08x, %08x ) %08x\n", offset, mem_mask, data );
	return data;
}

static WRITE32_HANDLER( atapi_w )
{
	running_machine &machine = space.machine();
	int reg;

//  printf( "atapi_w( %08x, %08x, %08x )\n", offset, mem_mask, data );

	if (mem_mask == 0x0000ffff)	// word-wide command write
	{
//      printf("atapi_w: data=%04x\n", data );

//      printf("ATAPI: packet write %04x\n", data);
		atapi_data[atapi_data_ptr++] = data & 0xff;
		atapi_data[atapi_data_ptr++] = data >> 8;

		if (atapi_cdata_wait)
		{
//                  printf("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait);
			if (atapi_data_ptr == atapi_cdata_wait)
			{
				// send it to the device
				gdrom->WriteData( atapi_data, atapi_cdata_wait );

				// assert IRQ
				gdrom_raise_irq(machine);

				// not sure here, but clear DRQ at least?
				atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
			}
		}

		else if ( atapi_data_ptr == 12 )
		{
			int phase;

//          printf("atapi_w: command %02x\n", atapi_data[0]&0xff );

			// reset data pointer for reading SCSI results
			atapi_data_ptr = 0;
			atapi_data_len = 0;

			// send it to the SCSI device
			gdrom->SetCommand( atapi_data, 12 );
			gdrom->ExecCommand( &atapi_xferlen );
			gdrom->GetPhase( &phase );

			if (atapi_xferlen != -1)
			{
				printf("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, atapi_xferlen);

				// store the returned command length in the ATAPI regs, splitting into
Esempio n. 16
0
bstring escapeColor(bstring color) {
    color.Replace("^","^^");
    return(color);
}
Esempio n. 17
0
const bstring Player::customColorize(bstring text, bool caret) const {
    text.Replace("*CC:BROADCAST*", getCustomColor(CUSTOM_COLOR_BROADCAST, caret).c_str());
    text.Replace("*CC:GOSSIP*", getCustomColor(CUSTOM_COLOR_GOSSIP, caret).c_str());
    text.Replace("*CC:PTEST*", getCustomColor(CUSTOM_COLOR_PTEST, caret).c_str());
    text.Replace("*CC:NEWBIE*", getCustomColor(CUSTOM_COLOR_NEWBIE, caret).c_str());
    text.Replace("*CC:DM*", getCustomColor(CUSTOM_COLOR_DM, caret).c_str());
    text.Replace("*CC:ADMIN*", getCustomColor(CUSTOM_COLOR_ADMIN, caret).c_str());
    text.Replace("*CC:SEND*", getCustomColor(CUSTOM_COLOR_SEND, caret).c_str());
    text.Replace("*CC:MESSAGE*", getCustomColor(CUSTOM_COLOR_MESSAGE, caret).c_str());
    text.Replace("*CC:WATCHER*", getCustomColor(CUSTOM_COLOR_WATCHER, caret).c_str());
    text.Replace("*CC:CLASS*", getCustomColor(CUSTOM_COLOR_CLASS, caret).c_str());
    text.Replace("*CC:RACE*", getCustomColor(CUSTOM_COLOR_RACE, caret).c_str());
    text.Replace("*CC:CLAN*", getCustomColor(CUSTOM_COLOR_CLAN, caret).c_str());
    text.Replace("*CC:TELL*", getCustomColor(CUSTOM_COLOR_TELL, caret).c_str());
    text.Replace("*CC:GROUP*", getCustomColor(CUSTOM_COLOR_GROUP, caret).c_str());
    text.Replace("*CC:DAMAGE*", getCustomColor(CUSTOM_COLOR_DAMAGE, caret).c_str());
    text.Replace("*CC:SELF*", getCustomColor(CUSTOM_COLOR_SELF, caret).c_str());
    text.Replace("*CC:GUILD*", getCustomColor(CUSTOM_COLOR_GUILD, caret).c_str());
    return(text);
}
Esempio n. 18
0
//---------------------------------------------------------------------
// update the file attributes
void Server::updateFileAttr(bstring const & path, bstring const & file, bstring const & attrs) {
  DirCache::iterator i = dirCache.find(path);
  if (i == dirCache.end())
    return;

  my_fxp_names * dir = i->second;
  int count = dir->nnames;
  for (int i = 0; i < count; ++i) {
    fxp_name * fn = dir->names[i];
#ifdef UNICODE
    if (file == fn->ucFilename) {
#else
    if (file == fn->filename) {
#endif
      // got it
      fn->attrs.permissions = bstrtol(attrs.c_str(), '\0', 8);
      return;
    }
  }
}

//---------------------------------------------------------------------
// CT
// init with zeros
Server::Server(bstring const & serverName) :
  name(serverName), currentMapper(0), disableMtime(false), myCfg(0) {
}

//---------------------------------------------------------------------
// free one fxp_name
static void freeFn(fxp_name * fn) {
  if (!fn)
    return;

  free(fn->filename);
  free(fn->longname);
  free(fn);
}

//---------------------------------------------------------------------
// free all fxp_names + my_fxp_names
static void freeMfn(my_fxp_names * dir) {
  if (!dir)
    return;

  for (int i = 0; i < dir->nnames; i++) {
    freeFn(dir->names[i]);
  }
  free(dir);
}

//---------------------------------------------------------------------
// DT
// free all cached structures
Server::~Server() {
  if (currentMapper && currentMapper->hDll && !currentMapper->disconnected()) {
    currentMapper->disconnect();
  }
  delete currentMapper;

  clearDirCache();

  delete myCfg;
}

bool Server::connect() {
  //	Guard guard(this);
  //	return guard.isConnected();
  return true;
}

//---------------------------------------------------------------------
// clear the folder chache
void Server::clearDirCache() {
  for (DirCache::iterator i = dirCache.begin(); i != dirCache.end(); ++i) {
    my_fxp_names * dir = i->second;
    freeMfn(dir);
  }
  dirCache.clear();
}

//---------------------------------------------------------------------
// performs a server lookup by evaluating the remote path
// on success the remote path is also set
Server * Server::findServer(bstring & remotePath, bchar const * const fullPath) {
  bstring serverName = *fullPath == TEXT('\\') ? fullPath + 1 : fullPath;
  int slash = (int) serverName.find_first_of(TEXT('\\'));
  if (slash > 0) {
    remotePath = serverName.substr(slash);
    for (bstring::iterator i = remotePath.begin(); i != remotePath.end(); ++i) {
      if (*i == TEXT('\\'))
        *i = '/';
    }
    serverName = serverName.substr(0, slash);
  } else {
    remotePath = TEXT("/");
  }

  ServerMap::const_iterator i = serverMap.find(serverName);
  Server * server;
  if (i != serverMap.end()) {
    server = i->second;
  } else {
    server = new Server(serverName);
    serverMap.insert(std::make_pair(serverName, server));
  }

  return server;
}