void NpcJanela(char *Packet)//Deseja continuar ? (sim/nao)" { p28B *p = (p28B*)Packet; MOB *player = (MOB*)GetMobFromIndex(p->Header.ClientID); MOB *npc = (MOB*)GetMobFromIndex(p->npcid); if(p->ClickOk == 1) { switch(npc->Merchant) { case 42: Merchant42(p->Header.ClientID,p->npcid); ZeroMemory((short*)Packet, *(short*)Packet); break; case 74: ZeroMemory((short*)Packet, *(short*)Packet); break; case 19: //ZeroMemory((short*)Packet, *(short*)Packet); break; default: SendSay(p->npcid,"Ainda não estou disponivel."); break; } } return; }
void CashNPC(int ClientID,int npcid) { FILE *arquivo; char cash[1000]; //char cash2[1000]; //char line[120], nome[100], msg[100]; // Retirar variáveis desnecessárias MOB *player = (MOB*)GetMobFromIndex(ClientID); MOB *vLogin = (MOB*)GetMobFromIndex(ClientID); int itenslot1 = GetFirstSlotSADD(ClientID,3394,64); if(itenslot1 != -1) { sprintf(cash,"DataBase\\Cash\\%s.txt",vLogin(ClientID)); if(file_exists(cash)) { arquivo = fopen(cash, "w"); fputs("1000", arquivo); fclose(arquivo); SendSay(npcid,"Obrigado por nos ajudar. Agora você possui 1000 Cash"); player->Inventory[itenslot1].Index = 0; SendInv(ClientID,itenslot1); SendCharList(ClientID); return; } else { arquivo = fopen(cash, "w"); fputs("1000", arquivo); fclose(arquivo); SendSay(npcid,"Obrigado por nos ajudar. Agora você possui 1000 Cash"); player->Inventory[itenslot1].Index = 0; SendInv(ClientID,itenslot1); SendCharList(ClientID); return; } } else { SendSay(npcid,"Nos Traga seu Vale Cash!"); return; } }
int main(int argc, char *argv[]) { char *domain; char *port_str; int port_num; char *username; std::string input; char *output = (char *) ""; fd_set read_set; int result; char stdin_buffer[SAY_MAX + 1]; char *stdin_buffer_pointer = stdin_buffer; char receive_buffer[kBufferSize]; memset(&receive_buffer, 0, kBufferSize); if (argc < 4) { Error("usage: client [server name] [port] [username]"); } domain = argv[1]; port_str = argv[2]; port_num = atoi(argv[2]); username = argv[3]; if (strlen(domain) > UNIX_PATH_MAX) { Error("client: server name must be less than 108 characters"); } if (port_num < 0 || port_num > 65535) { Error("client: port number must be between 0 and 65535"); } if (strlen(username) > USERNAME_MAX) { Error("client: username must be less than 32 characters"); } CreateSocket(domain, port_str); // SendLogin(username); // // current_channel = "Common"; // SendJoin(current_channel); if (raw_mode() != 0) { Error("client: error using raw mode"); } PrintPrompt(); while (1) { FD_ZERO(&read_set); FD_SET(client_socket, &read_set); FD_SET(STDIN_FILENO, &read_set); if ((result = select(client_socket + 1, &read_set, NULL, NULL, NULL)) < 0) { Error("client: problem using select"); } if (result > 0) { if (FD_ISSET(STDIN_FILENO, &read_set)) { // User entered a char. char c = (char) getchar(); if (c == '\n') { // Increments pointer and adds NULL char. *stdin_buffer_pointer++ = '\0'; // Resets stdin_buffer_pointer to the start of stdin_buffer. stdin_buffer_pointer = stdin_buffer; std::cout << "\n" << std::flush; // Prevents output from printing on the new prompt after a newline char. output = (char *) ""; input.assign(stdin_buffer, stdin_buffer + strlen(stdin_buffer)); if (input[0] == '/') { if (!ProcessInput(input)) { break; } } else { // Sends chat messages. if (current_channel != "") { SendSay(input); } else { PrintPrompt(); } } } else if (stdin_buffer_pointer != stdin_buffer + SAY_MAX) { // Increments pointer and adds char c. *stdin_buffer_pointer++ = c; std::cout << c << std::flush; // Copies pointer into output. output = stdin_buffer_pointer; // Increments and sets NULL char. *output++ = '\0'; // Copies stdin_buffer into part of output before NULL char. output = stdin_buffer; } } else if (FD_ISSET(client_socket, &read_set)) { // Socket has data. ssize_t read_size = read(client_socket, receive_buffer, kBufferSize); if (read_size != 0) { struct text message; memcpy(&message, receive_buffer, sizeof(struct text)); text_t text_type = message.txt_type; switch (text_type) { case TXT_SAY: HandleTextSay(receive_buffer, output); break; case TXT_LIST: HandleTextList(receive_buffer, output); break; case TXT_WHO: HandleTextWho(receive_buffer, output); break; case TXT_ERROR: HandleError(receive_buffer, output); break; default: break; } } memset(&receive_buffer, 0, SAY_MAX); } // end of if client_socket } // end of if result } // end of while return 0; }
/* * CommandEcho: Room-wide purple message without the name. */ void CommandEcho(char *args) { if (*args == 0) return; SendSay(SAY_MESSAGE, args); }
/* * CommandDM: "DM" say command by Chris! Yay! Infiltrating the client, slowly... */ void CommandDM(char *args) { if (*args == 0) return; SendSay(SAY_DM, args); }
void Exec_MSG_Challange(int conn, char *pMsg) { MSG_STANDARDPARM *m = (MSG_STANDARDPARM*)pMsg; int target = m->Parm; if (target <= 0 || target >= MAX_MOB) return; int zone = pMob[target].MOB.BaseScore.Level; if (zone < 0 || zone >= ValidGuild) return; if (zone != 5) { char ChargeName[256]; char ChallName[256]; int charge = g_pGuildZone[zone].ChargeGuild; int chall = g_pGuildZone[zone].ChallangeGuild; BASE_GetGuildName(ServerGroup, charge, ChargeName); BASE_GetGuildName(ServerGroup, chall, ChallName); if (WeekMode && WeekMode != 1 && WeekMode != 2 && WeekMode != 3) { if (WeekMode == 4) { if(pMob[conn].MOB.Guild && pMob[conn].MOB.Guild == g_pGuildZone[zone].ChargeGuild && pMob[conn].MOB.GuildLevel == 9) { long long Coin = (pMob[GuildImpostoID[zone]].MOB.Exp+1) / 1000000000; if(pMob[GuildImpostoID[zone]].MOB.Exp <= 0) { sprintf(temp, g_pMessageStringTable[_I64D_TOWN_TAX], pMob[target].MOB.Exp); SendSay(target, temp); return; } if(Coin == 0) { long long bGold = pMob[GuildImpostoID[zone]].MOB.Exp; long long fGold = pMob[GuildImpostoID[zone]].MOB.Exp + pMob[conn].MOB.Coin; if(fGold <= 2000000000) { SendClientMessage(conn, g_pMessageStringTable[_NN_GIVE_TOWN_TAX]); pMob[GuildImpostoID[zone]].MOB.Exp = 0; pMob[conn].MOB.Coin = fGold; SendEtc(conn); sprintf(temp, "etc,imposto recolhido(1) zone:%d coin:%llu", zone, bGold); Log(temp, pUser[conn].AccountName, pUser[conn].IP); return; } else { SendClientMessage(conn, g_pMessageStringTable[_NN_Cant_get_more_than_2G]); return; } } else { STRUCT_ITEM Item; memset(&Item, 0, sizeof(STRUCT_ITEM)); Item.sIndex = 4011; int i = 0; for(i = Coin; i > 0; i--) { if(PutItem(conn, &Item) == 0) return; pMob[GuildImpostoID[zone]].MOB.Exp -= 1000000000; sprintf(temp, "etc,imposto recolhido(2) zone:%d coin:%d", zone, 1); Log(temp, pUser[conn].AccountName, pUser[conn].IP); } SendClientMessage(conn, g_pMessageStringTable[_NN_GIVE_TOWN_TAX]); return; } } sprintf(temp, g_pMessageStringTable[_I64D_TOWN_TAX], pMob[target].MOB.Exp); SendSay(target, temp); } else if (WeekMode == 5) SendClientSignal(conn, 0, _MSG_ReqChallange); } else { if (g_pGuildZone[zone].ChallangeGuild) { sprintf(temp, g_pMessageStringTable[_DS_S_Challanged], pChallangerMoney[zone], ChallName); SendSay(target, temp); sprintf(temp, g_pMessageStringTable[_SS_Champion_And_Challanger], ChargeName, ChallName); SendSay(target, temp); } else { sprintf(temp, g_pMessageStringTable[_SN_No_Challanger], ChargeName); SendSay(target, temp); } } } }
void NPCGuerras(BYTE *m_PacketBuffer) { MOB *player = (MOB*)GetMobFromIndex(m_PacketBuffer[6]); MOB *npc = (MOB*)GetMobFromIndex(m_PacketBuffer[12]); if(strcmp((char*)npc->Name, "Kara") == 0) { FILE *fs = NULL; char line[120]; char *dono = NULL, *msg = NULL; int guild,apostado1,apostado2; fs = fopen("DataBase\\Guerras\\Azran.txt", "rt+"); if(fs != NULL) { while((fscanf(fs, "%[^\n]", line)) != EOF) { fgetc(fs); sscanf(line, "%s,%d,%d,%d",&dono[0], &guild, &apostado1, &apostado2); sprintf(msg, "A guilda [%s] foi a vencedora.", dono); SendSay(m_PacketBuffer[12],msg); } fclose(fs); } } if(strcmp((char*)npc->Name, "Empis") == 0) { FILE *fs = NULL; char line[120]; char *dono = NULL, *msg = NULL; // Incializando as variáveis com valores nulos, porém elas poderão assumir novos valores posteriormente int guild,apostado1,apostado2; fs = fopen("DataBase\\Guerras\\Erion.txt", "rt+"); if(fs != NULL) { while((fscanf(fs, "%[^\n]", line)) != EOF) { fgetc(fs); sscanf(line, "%s,%d,%d,%d",&dono[0], &guild, &apostado1, &apostado2); sprintf(msg, "A guilda [%s] foi a vencedora.", dono); SendSay(m_PacketBuffer[12],msg); } fclose(fs); } } if(strcmp((char*)npc->Name, "Balmus") == 0) { FILE *fs = NULL; char line[120]; char *dono = NULL, *msg = NULL; int guild,apostado1,apostado2; fs = fopen("DataBase\\Guerras\\Armia.txt", "rt+"); if(fs != NULL) { while((fscanf(fs, "%[^\n]", line)) != EOF) { fgetc(fs); sscanf(line, "%s,%d,%d,%d",&dono[0], &guild, &apostado1, &apostado2); sprintf(msg, "A guilda [%s] foi a vencedora.", dono); SendSay(m_PacketBuffer[12],msg); } fclose(fs); } } }
void ChatManager::HandleChatMessage(MsgEntry *me, Client *client) { psChatMessage msg(me); // Dont if (!msg.valid) { Debug2(LOG_NET,me->clientnum,"Received unparsable psChatMessage from client %u.\n",me->clientnum); return; } const char *pType = msg.GetTypeText(); if (msg.iChatType != CHAT_TELL && msg.iChatType != CHAT_AWAY) { Debug4(LOG_CHAT, client->GetClientNum(), "%s %s: %s\n", client->GetName(), pType, msg.sText.GetData()); } else { Debug5(LOG_CHAT,client->GetClientNum(), "%s %s %s: %s\n", client->GetName(), pType, msg.sPerson.GetData(),msg.sText.GetData()); } bool saveFlood = true; if (!client->IsMute()) { // Send Chat to other players switch (msg.iChatType) { case CHAT_GUILD: { SendGuild(client, msg); break; } case CHAT_ALLIANCE: { SendAlliance(client, msg); break; } case CHAT_GROUP: { SendGroup(client, msg); break; } case CHAT_AUCTION: case CHAT_SHOUT: { SendShout(client, msg); break; } case CHAT_CHANNEL: { csArray<uint32_t> subscribed = channelSubscriptions.GetAll(client->GetClientNum()); bool found = false; for(size_t i = 0; i < subscribed.GetSize(); i++) { if(subscribed[i] == msg.channelID) found = true; } if(!found) { psserver->SendSystemError(client->GetClientNum(), "You have not yet joined this channel."); break; } // channel 1 is public if(msg.channelID == 1) CPrintf (CON_WARNING, "Gossip %s: %s\n", client->GetName(), msg.sText.GetData()); psChatMessage newMsg(client->GetClientNum(), client->GetActor()->GetEID(), client->GetName(), 0, msg.sText, msg.iChatType, msg.translate, msg.channelID); csArray<uint32_t> subscribers = channelSubscribers.GetAll(msg.channelID); csArray<PublishDestination> destArray; for (size_t i = 0; i < subscribers.GetSize(); i++) { destArray.Push(PublishDestination(subscribers[i], NULL, 0, 0)); Client *target = psserver->GetConnections()->Find(subscribers[i]); if (target && target->IsReady()) target->GetActor()->LogChatMessage(client->GetActor()->GetFirstName(), newMsg); } newMsg.Multicast(destArray, 0, PROX_LIST_ANY_RANGE ); break; } case CHAT_PET_ACTION: { gemNPC *pet = NULL; // Check if a specific pet's name was specified, in one of these forms: // - /mypet Petname ... // - /mypet Petname's ... size_t numPets = client->GetNumPets(); for (size_t i = 0; i < numPets; i++) { if ((pet = dynamic_cast <gemNPC*>(client->GetPet(i))) && msg.sText.StartsWith(pet->GetCharacterData()->GetCharName(), true)) { size_t n = strlen(pet->GetCharacterData()->GetCharName()); if (msg.sText.Length() >= n + 1 && msg.sText.GetAt(n) == ' ') { msg.sText.DeleteAt(0, n); msg.sText.LTrim(); break; } else if (msg.sText.Length() >= n + 3 && msg.sText.GetAt(n) == '\'' && msg.sText.GetAt(n + 1) == 's' && msg.sText.GetAt(n + 2) == ' ') { msg.sText.DeleteAt(0, n); break; } } else pet = NULL; } // If no particular pet was specified, assume the default familiar... if (!pet) pet = dynamic_cast <gemNPC*>(client->GetFamiliar()); // Send the message or an appropriate error... if (!pet) psserver->SendSystemInfo(me->clientnum, "You have no familiar to command."); else SendSay(client->GetClientNum(), pet, msg, pet->GetCharacterData()->GetCharFullName()); break; } case CHAT_SAY: { // Send to all if there's no NPC response or the response is public SendSay(client->GetClientNum(), client->GetActor(), msg, client->GetName()); break; } case CHAT_NPC: { // Only the speaker sees his successful chatting with an npc. // This helps quests stay secret. //psChatMessage newMsg(client->GetClientNum(), client->GetName(), 0, // msg.sText, msg.iChatType, msg.translate); //newMsg.SendMessage(); saveFlood = false; gemObject *target = client->GetTargetObject(); gemNPC *targetnpc = dynamic_cast<gemNPC*>(target); NpcResponse *resp = CheckNPCResponse(msg,client,targetnpc); if (resp) { csTicks delay = resp->ExecuteScript(client->GetActor(), targetnpc); if (delay != (csTicks)-1 && resp->menu ) resp->menu->ShowMenu(client, delay, targetnpc); } break; } case CHAT_AWAY: { saveFlood = false; //do not check Away messages for flooding msg.iChatType = CHAT_TELL; //do regard it as tell message from now on //intentionally no break, so it falls through to CHAT_TELL } case CHAT_TELL: { if ( msg.sPerson.Length() == 0 ) { psserver->SendSystemError(client->GetClientNum(), "You must specify name of player."); break; } Client *target = FindPlayerClient(msg.sPerson); if (target && !target->IsSuperClient()) { if (!target->IsReady()) psserver->SendSystemError(client->GetClientNum(), "%s is not ready yet.", msg.sPerson.GetDataSafe()); else SendTell(msg, client->GetName(), client, target); } else psserver->SendSystemError(client->GetClientNum(), "%s is not found online.", msg.sPerson.GetDataSafe()); break; } case CHAT_REPORT: { // First thing to extract the name of the player to log csString targetName; int index = (int)msg.sText.FindFirst(' ', 0); targetName = (index == -1) ? msg.sText : msg.sText.Slice(0, index); targetName = NormalizeCharacterName(targetName); if ( targetName.Length() == 0 ) { psserver->SendSystemError(client->GetClientNum(), "You must specify name of player."); break; } Client * target = psserver->GetConnections()->Find(targetName); if ( !target ) { psserver->SendSystemError(client->GetClientNum(), "%s is not found online.", targetName.GetData()); break; } if (target->IsSuperClient()) { psserver->SendSystemError(client->GetClientNum(), "Can't report NPCs."); break; } // Add an active report to the target. if (target->GetActor()->AddChatReport(client->GetActor())) { // Add report removal event. psserver->GetEventManager()->Push(new psEndChatLoggingEvent(target->GetClientNum(), 300000)); psserver->SendSystemInfo(client->GetClientNum(), "Last 5 minutes of %s's chat were logged. Logging will continue for another 5 minutes.", targetName.GetData()); } else psserver->SendSystemError(client->GetClientNum(), "Could not start logging %s, due to a server error.", targetName.GetData()); break; } case CHAT_ADVISOR: case CHAT_ADVICE: break; default: { Error2("Unknown Chat Type: %d\n",msg.iChatType); break; } } } else { //User is muted but tries to chat anyway. Remind the user that he/she/it is muted psserver->SendSystemInfo(client->GetClientNum(),"You can't send messages because you are muted."); } if (saveFlood) client->FloodControl(msg.iChatType, msg.sText, msg.sPerson); }
void Merchant42(int ClientID, int npcid) { MOB *player = (MOB*)GetMobFromIndex(ClientID); MOB *npc = (MOB*)GetMobFromIndex(npcid); if (npc->Merchant == 42) { switch (npc->bStatus.Level) { case 1: //NPC Coveiro Quest_Cemiterio(ClientID, npcid); break; case 2: //NPC Jardim Quest_Jardim(ClientID, npcid); break; case 3: //NPC Kaizen Quest_Kaizen(ClientID, npcid); break; case 4: //NPC Hidra Quest_Hidra(ClientID, npcid); break; case 5: //NPC Elfos Quest_Elfo(ClientID, npcid); break; case 13: Kibita(ClientID, npcid); break; case 15: GodGover(ClientID, npcid); break; case 17: JuntaImortalidade(ClientID,npcid); break; case 28: MestreHabilidade(ClientID,npcid); break; case 29: ComporIdeal(ClientID,npcid); break; case 37: Ordem_Vento(ClientID,npcid); break; case 38: Ordem_Terra(ClientID,npcid); break; case 39: Ordem_Agua(ClientID,npcid); break; case 40: Ordem_Sol(ClientID,npcid); break; case 41: MestreGrifo(ClientID,npcid); break; case 42: Compor_Pedra_ReturnofGlory(ClientID,npcid); break; case 45: ReturnofGlory(ClientID,npcid); break; case 201: saldo(ClientID,npcid); break; case 202: QntdeGold(ClientID,npcid); break; default: SendSay(npcid, "Em Construçao !!!!"); break; } } return; }
void NPCDonate(BYTE *m_PacketBuffer) { FILE *arq, *arq2; int clientid = m_PacketBuffer[6]; p379 *pak = (p379*)m_PacketBuffer; MOB *player = (MOB*)GetMobFromIndex(m_PacketBuffer[6]); MOB *npc = (MOB*)GetMobFromIndex(pak->MobID); char local_item[100], line[120], nome[100], local_cash[100], msg[100],msg_confirm[100]; int slot_nulo = GetFirstSlotSADD(clientid,0,64); int preco, cash, confirm; sprintf(local_item,"DataBase\\Itens\\%d.txt",npc->Inventory[pak->SellSlot].Index); sprintf(local_cash,"DataBase\\Cash\\%s.txt",vLogin(clientid)); { arq=fopen(local_item,"r"); if(arq != NULL) { while((fscanf(arq, "%[^\n]", line)) != EOF) { fgetc(arq); sscanf(line,"%d,%s",&preco,&nome); } fclose(arq); arq2=fopen(local_cash,"r"); if(arq2 != NULL) { while((fscanf(arq2, "%[^\n]", line)) != EOF) { fgetc(arq2); sscanf(line,"%d",&cash); } fclose(arq2); if(cash >= preco) { player->Inventory[slot_nulo].Index = npc->Inventory[pak->SellSlot].Index; player->Inventory[slot_nulo].EF1 = npc->Inventory[pak->SellSlot].EF1; player->Inventory[slot_nulo].EFV1 = npc->Inventory[pak->SellSlot].EFV1; player->Inventory[slot_nulo].EF2 = npc->Inventory[pak->SellSlot].EF2; player->Inventory[slot_nulo].EFV2 = npc->Inventory[pak->SellSlot].EFV2; player->Inventory[slot_nulo].EF3 = npc->Inventory[pak->SellSlot].EF3; player->Inventory[slot_nulo].EFV3 = npc->Inventory[pak->SellSlot].EFV3; arq2=fopen(local_cash,"w"); fprintf(arq2,"%d",(cash - preco)); fclose(arq2); sprintf(msg,"O item [%s] foi comprado com sucesso.",nome); SendSay(clientid,msg); SendALL(clientid); ZeroMemory(m_PacketBuffer, *(short*)m_PacketBuffer); return; } else { fclose(arq2); sprintf(msg,"Necessário [%d] Donates.",preco); SendClientMsg(clientid,msg); ZeroMemory(m_PacketBuffer, *(short*)m_PacketBuffer); return; } } else { sprintf(msg,"Necessário [%d] Donates.",preco); SendClientMsg(clientid,msg); ZeroMemory(m_PacketBuffer, *(short*)m_PacketBuffer); return; } } } }