/** * \brief Enumerate the items that the server knows about */ void Server_Cmd_ENUMITEMS(tClient *Client, char *Args) { int i, count; if( Args != NULL && strlen(Args) ) { sendf(Client->Socket, "407 ENUM_ITEMS takes no arguments\n"); return ; } // Count shown items count = 0; for( i = 0; i < giNumItems; i ++ ) { if( gaItems[i].bHidden ) continue; count ++; } sendf(Client->Socket, "201 Items %i\n", count); for( i = 0; i < giNumItems; i ++ ) { if( gaItems[i].bHidden ) continue; Server_int_SendItem( Client, &gaItems[i] ); } sendf(Client->Socket, "200 List end\n"); }
/// Accept an incoming connection int RASocket::open(void* ) { if (reactor ()->register_handler(this, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK) == -1) { sLog.outError ("RASocket::open: unable to register client handler errno = %s", ACE_OS::strerror (errno)); return -1; } ACE_INET_Addr remote_addr; if (peer ().get_remote_addr (remote_addr) == -1) { sLog.outError ("RASocket::open: peer ().get_remote_addr errno = %s", ACE_OS::strerror (errno)); return -1; } sLog.out(LOG_RA, "Incoming connection from %s.",remote_addr.get_host_addr()); ///- print Motd sendf(sWorld.GetMotd()); sendf("\r\n"); sendf(sObjectMgr.GetMangosStringForDBCLocale(LANG_RA_USER)); return 0; }
static void connected(server *s) { /* Server successfully connected, send IRC init messages */ connection_thread *ct = s->connecting; if ((pthread_join(ct->tid, NULL))) fatal("pthread_join"); if (*ct->ipstr) newlinef(s->channel, 0, "--", "Connected to [%s]", ct->ipstr); else newlinef(s->channel, 0, "--", "Error determining server IP: %s", ct->error); s->soc = ct->socket; /* Set reconnect parameters to 0 in case this was an auto-reconnect */ s->reconnect_time = 0; s->reconnect_delta = 0; s->latency_time = time(NULL); s->latency_delta = 0; sendf(NULL, s, "NICK %s", s->nick); sendf(NULL, s, "USER %s 8 * :%s", config.username, config.realname); //FIXME: should the server send nick as is? compare the nick when it's received? //or should auto_nick take a server argument and write to a buffer of NICKSIZE length? }
/** * \brief Authenticate as a user * * Usage: PASS <hash> */ void Server_Cmd_PASS(tClient *Client, char *Args) { char *passhash; int flags; if( Server_int_ParseArgs(0, Args, &passhash, NULL) ) { sendf(Client->Socket, "407 PASS takes 1 argument\n"); return ; } // Pass on to cokebank Client->UID = Bank_GetUserAuth(Client->Salt, Client->Username, passhash); if( Client->UID == -1 ) { sendf(Client->Socket, "401 Auth Failure\n"); return ; } flags = Bank_GetFlags(Client->UID); if( flags & USER_FLAG_DISABLED ) { Client->UID = -1; sendf(Client->Socket, "403 Account Disabled\n"); return ; } if( flags & USER_FLAG_INTERNAL ) { Client->UID = -1; sendf(Client->Socket, "403 Internal account\n"); return ; } Client->bIsAuthed = 1; sendf(Client->Socket, "200 Auth OK\n"); }
void Server_Cmd_PINSET(tClient *Client, char *Args) { char *pinstr; int pin; if( Server_int_ParseArgs(0, Args, &pinstr, NULL) ) { sendf(Client->Socket, "407 PIN_SET takes 1 argument\n"); return ; } if( !isdigit(pinstr[0]) || !isdigit(pinstr[1]) || !isdigit(pinstr[2]) || !isdigit(pinstr[3]) || pinstr[4] != '\0' ) { sendf(Client->Socket, "407 PIN should be four digits\n"); return ; } pin = atoi(pinstr); if( !Client->bIsAuthed ) { sendf(Client->Socket, "401 Not Authenticated\n"); return ; } int uid = Client->EffectiveUID; if(uid == -1) uid = Client->UID; // Can only pinset yourself (well, the effective user) Bank_SetPin(uid, pin); sendf(Client->Socket, "200 Pin updated\n"); return ; }
void take_obj_list(struct char_data *ch,struct obj_data *o,int *amount,struct char_data *give_to) { char buf[MAX_STRING_LENGTH]; if (*amount<=0 && !o) return; if (o->contains) take_obj_list(ch,o->contains,amount,give_to); else if (o->next_content) take_obj_list(ch,o->next_content,amount,give_to); else { if (o->carried_by) obj_from_char(o); if (o->in_obj) obj_from_obj(o); *amount -= o->obj_flags.cost; sendf(ch,"Your %s is taken.\n",o->short_description); if (give_to) sendf(give_to,"You take his %s.\n",o->short_description); if (give_to) { sprintf(buf,"FINE: %d take from %s",o->virtual,GET_NAME(ch)); slog(buf); obj_to_char(o,give_to); o->held_for=mystrdup(GET_NAME(ch)); } else { sprintf(buf,"LINK: %d take from %s",o->virtual,GET_NAME(ch)); slog(buf); extract_obj(o); } }
unsigned int cmd_script(callbackp *callbacki) { char *domain = CONFIG_VAL(Server, domain, callbacki->g_ape->srv); char *script = NULL; int alloc = 0; APE_PARAMS_INIT(); if (domain == NULL) { send_error(callbacki->call_user, "NO_DOMAIN", "201", callbacki->g_ape); } else { char *autodom; if (strcmp(domain, "auto") == 0 && (autodom = JSTR(domain)) != NULL) { domain = autodom; #if 0 /* http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0120a6d65b8a970b-pi */ struct _http_header_line *hlines; for (hlines = callbacki->client->http.hlines; hlines != NULL; hlines = hlines->next) { if (strcasecmp(hlines->key.val, "host") == 0) { char *loc; char *newdom = xmalloc(sizeof(char) * (hlines->value.len + 1)); memset(newdom, '\0', hlines->value.len + 1); if ((loc = strrchr(hlines->value.val, '.')) != NULL) { int i, pos = 0; for (i = 0; i < hlines->value.len; i++, pos++) { newdom[pos] = hlines->value.val[i]; if (newdom[pos] == ':') { newdom[pos] = '\0'; break; } if (hlines->value.val[i] == '.' && &hlines->value.val[i] < loc) { pos = -1; } } newdom[pos] = '\0'; domain = newdom; alloc = 1; } } } #endif } sendf(callbacki->client->fd, callbacki->g_ape, "%s<html>\n<head>\n\t<script>\n\t\tdocument.domain=\"%s\"\n\t</script>\n", HEADER_DEFAULT, domain); if (alloc) { free(domain); } JFOREACH(scripts, script) { sendf(callbacki->client->fd, callbacki->g_ape, "\t<script type=\"text/javascript\" src=\"%s\"></script>\n", script); } sendbin(callbacki->client->fd, "</head>\n<body>\n</body>\n</html>", 30, 0, callbacki->g_ape); }
void Server_Cmd_USERFLAGS(tClient *Client, char *Args) { char *username, *flags, *reason=NULL; int mask=0, value=0; int uid; // Parse arguments if( Server_int_ParseArgs(1, Args, &username, &flags, &reason, NULL) ) { if( !flags ) { sendf(Client->Socket, "407 USER_FLAGS takes at least 2 arguments\n"); return ; } reason = ""; } // Check authentication if( !Client->bIsAuthed ) { sendf(Client->Socket, "401 Not Authenticated\n"); return ; } // Check permissions if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) ) { sendf(Client->Socket, "403 Not a coke admin\n"); return ; } // Get UID uid = Bank_GetAcctByName(username, 0); if( uid == -1 ) { sendf(Client->Socket, "404 User '%s' not found\n", username); return ; } // Parse flags if( Server_int_ParseFlags(Client, flags, &mask, &value) ) return ; if( giDebugLevel ) Debug(Client, "Set %i(%s) flags to %x (masked %x)\n", uid, username, mask, value); // Apply flags Bank_SetFlags(uid, mask, value); // Log the change Log_Info("Updated '%s' with flag set '%s' by '%s' - Reason: %s", username, flags, Client->Username, reason); // Return OK sendf(Client->Socket, "200 User Updated\n"); }
/* Send one file. */ static void get_file(int s, char *url) { /* Set www_dir to point to your web directory. */ char *www_dir = NULL; char bufo[512]; int n, w; const char *mime = NULL; const char *p = url + 1; if (*p == 0) p = "index.html"; char *p2 = strrchr(p, '.'); if (p2) { p2++; if (!strcmp(p2, "html")) mime = "text/html"; else if (!strcmp(p2, "htm")) mime = "text/html"; else if (!strcmp(p2, "css")) mime = "text/css"; else if (!strcmp(p2, "txt")) mime = "text/plain"; else if (!strcmp(p2, "png")) mime = "image/png"; else if (!strcmp(p2, "jpg")) mime = "image/jpg"; else if (!strcmp(p2, "class")) mime = "application/x-java-applet"; else if (!strcmp(p2, "jar")) mime = "application/java-archive"; else if (!strcmp(p2, "pdf")) mime = "application/pdf"; else if (!strcmp(p2, "swf")) mime = "application/x-shockwave-flash"; else if (!strcmp(p2, "ico")) mime = "image/vnd.microsoft.icon"; else if (!strcmp(p2, "js")) mime = "text/javascript"; } www_dir = getenv("www_dir"); snprintf(bufo, sizeof(bufo), "%s/%s", www_dir, p); FILE *f = fopen(bufo, "rb"); if (!f) { sendf(s, "HTTP/1.0 404 NOK\r\n\r\n"); return; } sendf(s, "HTTP/1.0 200 OK\r\n"); if (mime) sendf(s, "Content-Type: %s\r\n\r\n", mime); else sendf(s, "\r\n"); while ((n = fread(bufo, 1, sizeof(bufo), f)) > 0) if ((w = mysend(s, bufo, n)) < 0) break; fclose(f); }
unsigned int cmd_script(callbackp *callbacki) { char *domain = CONFIG_VAL(Server, domain, callbacki->g_ape->srv); if (domain == NULL) { send_error(callbacki->call_user, "NO_DOMAIN", "201", callbacki->g_ape); } else { int i; sendf(callbacki->fdclient, callbacki->g_ape, "%s<html>\n<head>\n\t<script>\n\t\tdocument.domain=\"%s\"\n\t</script>\n", HEADER, domain); for (i = 1; i <= callbacki->nParam; i++) { sendf(callbacki->fdclient, callbacki->g_ape, "\t<script type=\"text/javascript\" src=\"%s\"></script>\n", callbacki->param[i]); } sendbin(callbacki->fdclient, "</head>\n<body>\n</body>\n</html>", 30, callbacki->g_ape); } return (FOR_NOTHING); }
/** * \brief Send an item status to the client * \param Client Who to? * \param Item Item to send */ void Server_int_SendItem(tClient *Client, tItem *Item) { char *status = "avail"; if( Item->Handler->CanDispense ) { switch(Item->Handler->CanDispense(Client->UID, Item->ID)) { case 0: status = "avail"; break; case 1: status = "sold"; break; default: case -1: status = "error"; break; } } if( !gbNoCostMode && Item->Price == 0 ) status = "error"; // KNOWN HACK: Naming a slot 'dead' disables it if( strcmp(Item->Name, "dead") == 0 ) status = "sold"; // Another status? sendf(Client->Socket, "202 Item %s:%i %s %i %s\n", Item->Handler->Name, Item->ID, status, Item->Price, Item->Name ); }
/** * \brief Parses a client command and calls the required helper function * \param Client Pointer to client state structure * \param CommandString Command from client (single line of the command) * \return Heap String to return to the client */ void Server_ParseClientCommand(tClient *Client, char *CommandString) { char *command, *args; int i; if( giDebugLevel >= 2 ) Debug(Client, "Server_ParseClientCommand: (CommandString = '%s')", CommandString); if( Server_int_ParseArgs(1, CommandString, &command, &args, NULL) ) { if( command == NULL ) return ; // Is this an error? (just ignore for now) } // Find command for( i = 0; i < NUM_COMMANDS; i++ ) { if(strcmp(command, gaServer_Commands[i].Name) == 0) { if( giDebugLevel >= 2 ) Debug(Client, "CMD %s - \"%s\"", command, args); gaServer_Commands[i].Function(Client, args); return ; } } sendf(Client->Socket, "400 Unknown Command\n"); }
void _SendUserInfo(tClient *Client, int UserID) { char *type, *disabled="", *door=""; int flags = Bank_GetFlags(UserID); if( flags & USER_FLAG_INTERNAL ) { type = "internal"; } else if( flags & USER_FLAG_COKE ) { if( flags & USER_FLAG_ADMIN ) type = "coke,admin"; else type = "coke"; } else if( flags & USER_FLAG_ADMIN ) { type = "admin"; } else { type = "user"; } if( flags & USER_FLAG_DISABLED ) disabled = ",disabled"; if( flags & USER_FLAG_DOORGROUP ) door = ",door"; // TODO: User flags/type sendf( Client->Socket, "202 User %s %i %s%s%s\n", Bank_GetAcctName(UserID), Bank_GetBalance(UserID), type, disabled, door ); }
//SNP process uses this function to send a sendseg_arg_t structure which contains a segment and its src node ID to the SRT process. //Parameter tran_conn is the TCP descriptor of the connection between the SRT process and the SNP process. //Return 1 if a sendseg_arg_t is succefully sent, otherwise return -1. int forwardsegToSRT(int tran_conn, int src_nodeID, seg_t* segPtr) { sendseg_arg_t a; a.nodeID = src_nodeID; memcpy(&a.seg, segPtr, sizeof(seg_t)); return sendf(&a, tran_conn); }
//SRT process uses this function to send a segment and its destination node ID in a sendseg_arg_t structure to SNP process to send out. //Parameter network_conn is the TCP descriptor of the connection between the SRT process and the SNP process. //Return 1 if a sendseg_arg_t is succefully sent, otherwise return -1. int snp_sendseg(int network_conn, int dest_nodeID, seg_t* segPtr) { sendseg_arg_t a; a.nodeID = dest_nodeID; memcpy(&a.seg, segPtr, sizeof(seg_t)); return sendf(&a, network_conn); }
void command_debug_ping(uint32_t *args) { uint8_t len = args[0]; char *data = (void*)(size_t)args[1]; sendf("pong data=%*s", len, data); }
void command_debug_read8(uint32_t *args) { uint8_t *ptr = (void*)(size_t)args[0]; uint16_t v = *ptr; sendf("debug_result val=%hu", v); }
static PyObject *sendAuthChallenge(PyObject *self, PyObject *args) { //cn, domain, reqid, publicKey //return answer to challenge int cn; char *domain; uint id; char *publicKey; server::clientinfo *ci; if(!PyArg_ParseTuple(args, "isIs", &cn, &domain, &id, &publicKey)) return 0; ci = server::getinfo(cn); if(!ci) { PyErr_SetString(PyExc_ValueError, "Invalid cn specified"); return 0; } uint seed[3] = { randomMT(), randomMT(), randomMT() }; vector<char> challengeBuf; vector<char> answerBuf; void *parsedKey = parsepubkey(publicKey); genchallengestr(parsedKey, seed, sizeof(seed), challengeBuf, answerBuf); freepubkey(parsedKey); sendf(ci->clientnum, 1, "risis", N_AUTHCHAL, domain, id, challengeBuf.getbuf()); return Py_BuildValue("s", answerBuf.getbuf()); }
int basic_auth (SOCKET s ) { char *cred, *user = relay_user, *pass= relay_pass; int len, ret; char * userpass= NULL; if (user == NULL) { g_error("Cannot decide username for proxy authentication.(%s,%d)",__FILE__, __LINE__); return -1; } if (pass == NULL) { g_error("Can not decide password for proxy authentication.(%s,%d)", __FILE__, __LINE__); } // if ((pass = determine_relay_password ()) == NULL && // (pass = readpass("Enter proxy authentication password for %s@%s: ", //relay_user, relay_host)) == NULL) // g_error("Cannot decide password for proxy authentication."); len = strlen(user)+strlen(pass)+1; userpass = xmalloc(len+1); snprintf(userpass, len+1, "%s:%s", user, pass); //memset (pass, 0, strlen(pass)); cred = make_base64_string(userpass); memset (userpass, 0, len); ret = sendf(s, "Proxy-Authorization: Basic %s\r\n", cred); memset(cred, 0, strlen(cred)); free(cred); return ret; }
static int check_latency(server *s, time_t t) { /* Check time since last message */ time_t delta; if (s->soc < 0) return 0; delta = t - s->latency_time; /* Server has timed out */ if (delta > SERVER_TIMEOUT_S) { server_disconnect(s, 1, 0, "Ping timeout (" STR(SERVER_TIMEOUT_S) ")"); return 1; } /* Server might be timing out, attempt to PING */ if (delta > SERVER_LATENCY_PING_S && !s->pinging) { sendf(NULL, s, "PING :%s", s->host); s->pinging = 1; } /* Server hasn't responded to PING, display latency in status */ if (delta > SERVER_LATENCY_S && ccur->server == s) { s->latency_delta = delta; draw(D_STATUS); } return 0; }
static PyObject *playerMessageAll(PyObject *self, PyObject *args) { int cn; int tcn; char *text; server::clientinfo *ci; server::clientinfo *tci; if(!PyArg_ParseTuple(args, "iis", &cn, &tcn, &text)) return 0; ci = server::getinfo(cn); tci = server::getinfo(tcn); if(!ci) { PyErr_SetString(PyExc_ValueError, "Invalid cn specified"); return 0; } if(!tci) { PyErr_SetString(PyExc_ValueError, "Invalid cn specified"); return 0; } sendf(tci->clientnum, 1, "riiiis", N_CLIENT, ci->clientnum, strlen(text)+2, N_TEXT, text); Py_INCREF(Py_None); return Py_None; }
/** * \brief Set effective user */ void Server_Cmd_SETEUSER(tClient *Client, char *Args) { char *username; int eUserFlags, userFlags; if( Server_int_ParseArgs(0, Args, &username, NULL) ) { sendf(Client->Socket, "407 SETEUSER takes 1 argument\n"); return ; } if( !strlen(Args) ) { sendf(Client->Socket, "407 SETEUSER expects an argument\n"); return ; } // Check authentication if( !Client->bIsAuthed ) { sendf(Client->Socket, "401 Not Authenticated\n"); return ; } // Check user permissions userFlags = Bank_GetFlags(Client->UID); if( !(userFlags & (USER_FLAG_COKE|USER_FLAG_ADMIN)) ) { sendf(Client->Socket, "403 Not in coke\n"); return ; } // Set id Client->EffectiveUID = Bank_GetAcctByName(username, 0); if( Client->EffectiveUID == -1 ) { sendf(Client->Socket, "404 User not found\n"); return ; } // You can't be an internal account (unless you're an admin) if( !(userFlags & USER_FLAG_ADMIN) ) { eUserFlags = Bank_GetFlags(Client->EffectiveUID); if( eUserFlags & USER_FLAG_INTERNAL ) { Client->EffectiveUID = -1; sendf(Client->Socket, "404 User not found\n"); return ; } } // Disabled accounts // - If disabled and the actual user is not an admin (and not root) // return 403 if( (eUserFlags & USER_FLAG_DISABLED) && (Client->UID == 0 || !(userFlags & USER_FLAG_ADMIN)) ) { Client->EffectiveUID = -1; sendf(Client->Socket, "403 Account disabled\n"); return ; } sendf(Client->Socket, "200 User set\n"); }
void command_debug_read16(uint32_t *args) { uint16_t *ptr = (void*)(size_t)args[0]; irqstatus_t flag = irq_save(); uint16_t v = *ptr; irq_restore(flag); sendf("debug_result val=%hu", v); }
/** * \brief Fetch information on a specific item * * Usage: ITEMINFO <item ID> */ void Server_Cmd_ITEMINFO(tClient *Client, char *Args) { tItem *item; char *itemname; if( Server_int_ParseArgs(0, Args, &itemname, NULL) ) { sendf(Client->Socket, "407 ITEMINFO takes 1 argument\n"); return ; } item = _GetItemFromString(Args); if( !item ) { sendf(Client->Socket, "406 Bad Item ID\n"); return ; } Server_int_SendItem( Client, item ); }
/** * \brief Transfer money to another account * * Usage: GIVE <dest> <ammount> <reason...> */ void Server_Cmd_GIVE(tClient *Client, char *Args) { char *recipient, *ammount, *reason; int uid, iAmmount; int thisUid; // Parse arguments if( Server_int_ParseArgs(1, Args, &recipient, &ammount, &reason, NULL) ) { sendf(Client->Socket, "407 GIVE takes only 3 arguments\n"); return ; } // Check for authed if( !Client->bIsAuthed ) { sendf(Client->Socket, "401 Not Authenticated\n"); return ; } // Get recipient uid = Bank_GetAcctByName(recipient, 0); if( uid == -1 ) { sendf(Client->Socket, "404 Invalid target user\n"); return ; } // You can't alter an internal account // if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) { // sendf(Client->Socket, "404 Invalid target user\n"); // return ; // } // Parse ammount iAmmount = atoi(ammount); if( iAmmount <= 0 ) { sendf(Client->Socket, "407 Invalid Argument, ammount must be > zero\n"); return ; } if( Client->EffectiveUID != -1 ) { thisUid = Client->EffectiveUID; } else { thisUid = Client->UID; } // Do give switch( DispenseGive(Client->UID, thisUid, uid, iAmmount, reason) ) { case 0: sendf(Client->Socket, "200 Give OK\n"); return ; case 2: sendf(Client->Socket, "402 Poor You\n"); return ; default: sendf(Client->Socket, "500 Unknown error\n"); return ; } }
int zappy_connect_nbr(t_fds *c, char *_) { t_player *p; (void)_; if (!c || !(p = *(t_player**)c) || !p->team) return (false); sendf(c, "%d", p->team->max_conn); return (true); }
void command_spi_transfer(uint32_t *args) { uint8_t oid = args[0]; struct spidev_s *spi = oid_lookup(oid, command_config_spi); uint8_t data_len = args[1]; uint8_t *data = (void*)(size_t)args[2]; spidev_transfer(spi, 1, data_len, data); sendf("spi_transfer_response oid=%c response=%*s", oid, data_len, data); }
// Report the current position of the stepper void command_stepper_get_position(uint32_t *args) { uint8_t oid = args[0]; struct stepper *s = stepper_oid_lookup(oid); irq_disable(); uint32_t position = stepper_get_position(s); irq_enable(); sendf("stepper_position oid=%c pos=%i", oid, position - POSITION_BIAS); }
void sports_cast(char * fmt, ...) { va_list args; char s[MAX_STRING_LENGTH]; struct connection_data *i; va_start(args, fmt); vsprintf(s, fmt, args); va_end(args); for (i = connection_list; i ; i = i->next) if(!i->connected && !IS_SET(i->character->specials.act, PLR_NOSPORTS)) sendf(i->character,"SPORTS NEWS: %s\n",s); }
bool ok_to_use(CHAR_DATA *ch, const struct lookup_type *table, int value) { int minlev = level_table_lookup(table, value); if (minlev > get_trust(ch)) { sendf(ch, "You must be level %d to use this value.\n\r", minlev); return FALSE; } return TRUE; }