void go_name(CHAR_DATA* ch, CHAR_DATA* vict, int action) { int god_level = PRF_FLAGGED(ch, PRF_CODERINFO) ? LVL_IMPL : GET_LEVEL(ch); if (GET_LEVEL(vict) > god_level) { send_to_char("А он ведь старше вас...\r\n", ch); return; } // одобряем или нет int lev = NAME_GOD(vict); if (lev > 1000) lev = lev - 1000; if (lev > god_level) { send_to_char("Об этом имени уже позаботился бог старше вас.\r\n", ch); return; } if (lev == god_level) if (NAME_ID_GOD(vict) != GET_IDNUM(ch)) send_to_char("Об этом имени уже позаботился другой бог вашего уровня.\r\n", ch); if (action == NAME_AGREE) { NAME_GOD(vict) = god_level + 1000; NAME_ID_GOD(vict) = GET_IDNUM(ch); //send_to_char("Имя одобрено!\r\n", ch); send_to_char(vict, "&GВаше имя одобрено!&n\r\n"); agree_name(vict, GET_NAME(ch), god_level); if(GET_SEX(ch) == 0) sprintf(buf, "&c%s одобрило имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); if(GET_SEX(ch) == 1) sprintf(buf, "&c%s одобрил имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); if(GET_SEX(ch) == 2) sprintf(buf, "&c%s одобрила имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); if(GET_SEX(ch) == 3) sprintf(buf, "&c%s одобрили имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); send_to_gods(buf, true); // В этом теперь нет смысла //mudlog(buf, CMP, LVL_GOD, SYSLOG, TRUE); } else { NAME_GOD(vict) = god_level; NAME_ID_GOD(vict) = GET_IDNUM(ch); //send_to_char("Имя запрещено!\r\n", ch); send_to_char(vict, "&RВаше имя запрещено!&n\r\n"); disagree_name(vict, GET_NAME(ch), god_level); if(GET_SEX(ch) ==0) sprintf(buf, "&c%s запретило имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); if(GET_SEX(ch) ==1) sprintf(buf, "&c%s запретил имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); if(GET_SEX(ch) ==2) sprintf(buf, "&c%s запретила имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); if(GET_SEX(ch) ==3) sprintf(buf, "&c%s запретили имя игрока %s.&n\r\n", GET_NAME(ch), GET_NAME(vict)); send_to_gods(buf, true); //mudlog(buf, CMP, LVL_GOD, SYSLOG, TRUE); } }
void tBroadwave::initialiseBroadwave() { #if defined VISUAL_STUDIO // Initialize Winsock. int iResult = WSAStartup(MAKEWORD(2,2), &this->wsaData); if (iResult != NO_ERROR) { cerr << "Error with WSAStartup while initialising Broadwave.\n"; } else { cout << "Broadwave: WSAStarup() okay.\n"; } #endif // Create a socket. this->m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (this->m_socket == INVALID_SOCKET) { #if defined VISUAL_STUDIO cerr << "Client: socket() - Error at socket(): " << WSAGetLastError() << "\n"; WSACleanup(); #endif return; } else { cout << "Broadwave: socket() okay.\n"; } #if defined VISUAL_STUDIO u_long nonBlocking = 1; ioctlsocket(this->m_socket, FIONBIO, &nonBlocking); #elif defined LINUX_GCC // make sure socket doesn't block if (fcntl( this->m_socket, F_SETFL, FNDELAY ) == -1) throw runtime_error ("fcntl on control socket"); #endif struct linger ld = linger (); // zero it // Don't allow closed sockets to linger if (setsockopt(this->m_socket, SOL_SOCKET, SO_LINGER, (char *) &ld, sizeof ld ) == -1) throw runtime_error ("setsockopt (SO_LINGER)"); int x = 1; // Allow address reuse if (setsockopt( this->m_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &x, sizeof x ) == -1) throw runtime_error ("setsockopt (SO_REUSEADDR)"); // Connect to a server. this->clientService.sin_family = AF_INET; this->clientService.sin_addr.s_addr = inet_addr(BROADWAVE_IP); this->clientService.sin_port = htons(BROADWAVE_PORT); #if defined VISUAL_STUDIO if (connect(this->m_socket, (SOCKADDR*)&this->clientService, sizeof(this->clientService)) == SOCKET_ERROR) { cerr << "Client: connect() - Failed to connect.\n"; WSACleanup(); #elif defined LINUX_GCC if (connect(this->m_socket, (sockaddr*)&this->clientService, sizeof(this->clientService)) == 0) //if (connect(this->m_socket, &this->clientService, sizeof(this->clientService)) == 0) { cerr << "Client: connect() - Failed to connect.\n"; #endif return; } this->initialised = true; // Login tBroadwave::loginBroadwave (); } void tBroadwave::listenBroadwave () { if (!this->initialised) { return; } static vector<char> inbuf (1000); #if defined VISUAL_STUDIO int nRead = recv(this->m_socket, &inbuf [0], (int) inbuf.size(), 0); if (nRead == -1) { if (errno != WSAEWOULDBLOCK) { perror("read from broadwave"); } return; } if (nRead <= 0) { closesocket(this->m_socket); cerr << "Connection to Broadwave [" << this->m_socket << "] closed " << endl; this->m_socket = NO_SOCKET; return; } #elif defined LINUX_GCC int nRead = read(this->m_socket, &inbuf [0], (int)inbuf.size()); if (nRead == -1) { if (errno != EWOULDBLOCK) { perror ("read from broadwave"); } return; } if (nRead <= 0) { close(this->m_socket); cout << "Connection " << this->m_socket << " closed" << endl; this->m_socket = NO_SOCKET; return; } #endif string input; input += string(&inbuf[0], nRead); while (true) { string::size_type i = input.find("\n"); if (i == string::npos) { break; } string sLine = input.substr(0, i); input = input.substr(i + 1, string::npos); // This is where telnet negotiations occur if (sLine[0] == IAC) { string MCCP; MCCP.push_back(IAC); MCCP.push_back(WILL); MCCP.push_back(COMPRESS2); if (sLine.compare(0, 3, MCCP)) { // This assumes that MCCP is not available. // Send IAC WONT COMPRESS2 here } sLine.erase(0, 3); } else if (sLine[0] == '~') // System Command from Broadwave { sLine.erase(0, 1); if (sLine == "loginok") { cout << "Successfully logged in to Broadwave Server." << endl; } else if (sLine == "shutdown") { string outstring = "The Broadwave Server has been remotely shut down."; // PLACEHOLDER - Server Shutdown // If we've entered this else if, then the broadwave server has been shut down. // The string outstring contains that message - you'll need to use your MUD's // code to broadcast it. send_to_gods(outstring.c_str()); } continue; } if (!sLine.empty()) { istringstream is (sLine); string subwave, actor, realm, message; is >> subwave >> actor >> ws; string remnants; getline(is, remnants); realm = remnants.substr(0, remnants.find('*')); message = remnants.substr(remnants.find('*')+1, string::npos); string outstring; if (realm == THIS_REALM) { outstring = "[" + subwave + ":" + actor + "] " + message; } else { outstring = "[" + subwave + ":" + actor + "(" + realm + ")] " + message; } send_to_gods(outstring.c_str()); } } }
void close_socket (DESCRIPTOR_DATA * d) { DESCRIPTOR_DATA *tmp; char buf[100]; if (d->connected == CON_SOFT_REBOOT) /* Soft reboot sockets. */ return; if (d->character) /* I don't know about this one. . . */ d->character->desc = 0; close (d->hSocketFD); flush_queues (d); if (d->hSocketFD == maxdesc) --maxdesc; if (d->character && d->connected != CON_PLYNG) { unload_pc (d->character); d->character = NULL; } else if (d->character && d->connected == CON_PLYNG) { if (d->character->pc) d->character->pc->last_disconnect = time (0); save_char (d->character, true); /* KLUDGE: If the player is disconnecting is staff, he will get a message about himself disconnecting. However, he will be gone before that message gets to him, and the message will sit around in memory. By saying he isn't connected, the message will not be sent. (connected = -1) */ if (d->original) { d->character = d->original; d->original = NULL; } sprintf (s_buf, "%s has lost link.\n", d->character->tname); d->connected = CON_LINKDEAD; send_to_gods (s_buf); d->connected = CON_PLYNG; if (d->snoop.snooping && d->snoop.snooping->desc) { d->snoop.snooping->desc->snoop.snoop_by = 0; d->snoop.snooping = 0; } if (d->snoop.snoop_by && d->snoop.snoop_by->desc) { d->snoop.snoop_by->desc->snoop.snooping = 0; d->snoop.snoop_by = 0; } if (d->character->pc) d->character->pc->owner = 0; if (IS_MORTAL (d->character) && !IS_SET (d->character->flags, FLAG_GUEST)) { act ("$n has lost link.", true, d->character, 0, 0, TO_ROOM); sprintf (buf, "Closing link to: %s.", GET_NAME (d->character)); system_log (buf, false); d->character->desc = 0; } else if (IS_SET (d->character->flags, FLAG_GUEST)) do_quit (d->character, "", 0); } if (d->acct) delete d->acct; if (next_to_process == d) next_to_process = next_to_process->next; if (d == descriptor_list) { /* this is the head of the list */ descriptor_list = descriptor_list->next; } else { for (tmp = descriptor_list; tmp->next; tmp = tmp->next) if (tmp->next == d) { tmp->next = tmp->next->next; break; } } d->next = NULL; free_descriptor (d); socket_closed = true; }
void create_guest_avatar (DESCRIPTOR_DATA * d, char *argument) { CHAR_DATA *ch = NULL; char buf[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char account_name[MAX_STRING_LENGTH]; char tname_buf[MAX_STRING_LENGTH]; int roll, i = 1; extern int finished_booting; extern int guest_conns; if (!d) return; *buf = '\0'; *buf2 = '\0'; *account_name = '\0'; *tname_buf = '\0'; if (d->character) extract_char (d->character); sprintf (tname_buf, "%s-Guest", d->acct->name.c_str ()); d->character = new_char (1); //clear_char (d->character); d->character->deleted = 0; d->original = NULL; ch = d->character; ch->color = d->acct->color; d->character->pc->create_state = STATE_APPROVED; d->prompt_mode = 1; d->character->desc = d; d->character->pc->owner = d; d->character->pc->load_count = 1; roll = number (1, 11); if (roll == 1) ch->race = 0; else if (roll == 2) ch->race = 21; else if (roll == 3) ch->race = 16; else if (roll == 4) ch->race = 23; else if (roll == 5) ch->race = 120; else if (roll == 6) ch->race = 119; else if (roll == 7) ch->race = 89; else if (roll == 8) ch->race = 3; else if (roll == 9) ch->race = 28; else if (roll == 10) ch->race = 69; else if (roll == 11) ch->race = 64; else ch->race = 0; d->character->race = ch->race; d->character->flags |= FLAG_GUEST; /* Bestow the random traits to the new guest avatar */ randomize_mobile (ch); ch->pc->account_name = duplicateString (d->acct->name.c_str ()); if (is_guide (d->acct->name.c_str ())) ch->pc->is_guide = true; ch->fight_mode = 2; ch->clans = duplicateString (""); /* Address naming issues with our user's new account handle */ ch->tname = duplicateString (tname_buf); if (ch->pc->is_guide) sprintf (buf2, "%s Guide %s", ch->name, ch->tname); else sprintf (buf2, "%s %s", ch->name, ch->tname); if (ch->name) free_mem (ch->name); ch->name = duplicateString (buf2); ch->hit = 100; ch->max_hit = 100; ch->move = 100; ch->max_move = 100; if (d->character->race >= 0 && d->character->race <= 120) { for (i = 0; i <= MAX_SKILLS; i++) { d->character->skills[i] = 0; d->character->pc->skills[i] = 0; } //Get the native tongue of each race and cap it - Vader int native_tongue = get_native_tongue(ch); if (native_tongue) { ch->skills[native_tongue] = calc_lookup (ch, REG_CAP, native_tongue); ch->pc->skills[native_tongue] = calc_lookup (ch, REG_CAP, native_tongue); } ch->speaks = native_tongue; } guest_conns++; if (ch->description) free_mem (ch->description); if (ch->pc->is_guide) ch->description = duplicateString ("One of our friendly player #BGuides#0 is here, awaiting questions.\n"); else ch->description = duplicateString ("Another Guest is here, passing through. Be sure to welcome them!\n"); ch->plr_flags |= NEWBIE_HINTS; if (is_admin (ch->pc->account_name)) { ch->flags |= FLAG_ISADMIN; ch->flags |= FLAG_WIZNET; } else ch->flags &= ~FLAG_ISADMIN; if (ch->race != 89 && ch->race != 69 && ch->race != 64) equip_newbie (ch); else if (ch->race == 64) equip_char (ch, load_object (5261), WEAR_BODY); ch->hunger = -1; ch->thirst = -1; // If we're recreating, we're either recovering from a reboot or returning a dead // guest to the lounge, in which case we can skip a lot of this. pc_to_game (ch); char_to_room (ch, OOC_LOUNGE); if (str_cmp (argument, "recreate")) { act ("$n is incarnated in a soft glimmer of light.", true, d->character, 0, 0, TO_ROOM | _ACT_FORMAT); sprintf (buf, "%s [%s] has entered the lounge.", ch->tname, ch->desc->strClientHostname); send_to_gods (buf); d->connected = CON_PLYNG; guest_conns++; sprintf (buf, "%s has logged in from %s as %s.", char_short (d->character), d->strClientHostname, d->character->tname); *buf = toupper (*buf); system_log (buf, false); mysql_safe_query ("UPDATE newsletter_stats SET guest_logins=guest_logins+1"); do_look (ch, "", 0); } else { if (finished_booting) // Dead Guest being returned to the lounge. act ("$n appears in a sudden glimmer of light, looking slightly dazed.", true, ch, 0, 0, TO_ROOM | _ACT_FORMAT); act ("You feel your form briefly waver before it solidifies into yet another new guise, returned safely to the pleasant confines of Club Endore.", false, ch, 0, 0, TO_CHAR | _ACT_FORMAT); } }