void KickBan(int ban, char *source, struct Channel *channel, char *nicks, char *reason) { char *mask, *tempnix, **av, *bans; char temp[MAXLINE]; int ac, ii; struct Luser *lptr; if (!source || !channel || !nicks) return; tempnix = MyStrdup(nicks); ac = SplitBuf(tempnix, &av); if (ban) { bans = (char *) MyMalloc(sizeof(char)); bans[0] = '\0'; for (ii = 0; ii < ac; ii++) { if (!(lptr = FindClient(av[ii]))) continue; mask = HostToMask(lptr->username, lptr->hostname); ircsprintf(temp, "*!%s", mask); bans = (char *) MyRealloc(bans, strlen(bans) + strlen(temp) + (2 * sizeof(char))); strcat(bans, temp); strcat(bans, " "); MyFree(mask); } SetModes(source, 1, 'b', channel, bans); MyFree(bans); } for (ii = 0; ii < ac; ii++) { toserv(":%s REMOVE %s %s :%s\n", source, channel->name, av[ii], reason ? reason : ""); RemoveFromChannel(channel, FindClient(av[ii])); } MyFree(tempnix); MyFree(av); } /* KickBan() */
//Sends the actual message bool Server::SendString(int ID, std::string & _string) { if(_string.find("InitChess") != std::string::npos) { if (!SendPacketType(ID, P_GameStateChange)) return false; } else if(_string.find("MOVE:") != std::string::npos) { if (!SendPacketType(ID, P_ChessMove)) return false; } else { if (!SendPacketType(ID, P_ChatMessage)) return false; } int bufferlength = _string.size(); if (!SendInt(ID, bufferlength)) return false; int RetnCheck = send(players[FindClient(ID)].connection, _string.c_str(), bufferlength, NULL); if (RetnCheck == SOCKET_ERROR) return false; return true; }
//Retrieves the type of message bool Server::GetPacketType(int ID, Packet & _packettype) { int RetnCheck = recv(players[FindClient(ID)].connection, (char*)&_packettype, sizeof(Packet), NULL); if (RetnCheck == SOCKET_ERROR) return false; return true; }
//Sends the size of the message first bool Server::SendInt(int ID, int _int) { int RetnCheck = send(players[FindClient(ID)].connection, (char*)&_int, sizeof(int), NULL); if (RetnCheck == SOCKET_ERROR) return false; return true; }
void CClientMgr::SetClientAuthSucceed(int32 clientid) { CClient *cl = FindClient(clientid); if (!cl) return; cl->SetAlreadyAuth(); }
static PSERVICE_CLIENT AddClient( PSERVICE_ROUTE pid ) { { PSERVICE_CLIENT client = FindClient( pid ); if( client ) { //Log( WIDE("Client has reconnected?!?!?!") ); // reconnect is done when requesting a service from // a server that supplies one or more services itself... // suppose we can just let him continue... return client; } } { PSERVICE_CLIENT client = New( SERVICE_CLIENT ); MemSet( client, 0, sizeof( SERVICE_CLIENT ) ); client->route = pid[0]; client->last_time_received = timeGetTime(); client->flags.valid = 1; LinkThing( g.clients, client ); g.clients = client; //Log( WIDE("Added client...") ); return client; } }
// error的时候调用 void CServer::OnError(PER_IO_OPERATION_DATA *pPerIOData,long lIndexID,int errorCode) { if(NULL == pPerIOData) return; char str[200]; if(pPerIOData->OperationType == SOT_Send) { sprintf(str, "完成端口线程产生一次失败的发送IO操作(ErrorID:%d)。",errorCode); CBaseMessage* pMsg = (CBaseMessage*)pPerIOData->pParam; if(pMsg->RemoveRefCount() == 0) CBaseMessage::FreeMsg(pMsg); } else if(pPerIOData->OperationType == SOT_Receive) { sprintf(str, "完成端口线程产生一次失败的接受IO操作(ErrorID:%d)。",errorCode); m_pDBAllocator->FreeDB((CDataBlock*)pPerIOData->pParam); } CServerClient *pClient = FindClient(lIndexID); if(pClient) { //取消超时监视 if(pClient->IsAccept()) RemoveNewAcceptSocket(pClient->GetIndexID()); pClient->OnClose(); FreeClient(pClient); } FreeIoOper(pPerIOData); if(errorCode != 64) { PutTraceString(NET_MODULE,str); } }
/** Select a window for performing an action. */ void ChooseWindow(const MenuAction *action) { XEvent event; ClientNode *np; GrabMouseForChoose(); for(;;) { WaitForEvent(&event); if(event.type == ButtonPress) { if(event.xbutton.button == Button1) { np = FindClient(event.xbutton.subwindow); if(np) { client = np; RunWindowCommand(action); } } break; } else if(event.type == KeyPress) { break; } } JXUngrabPointer(display, CurrentTime); }
//当关闭的时候 void CServer::OnClose(PER_IO_OPERATION_DATA *pPerIOData,long lIndexID) { if(NULL == pPerIOData) return; if(pPerIOData->OperationType == SOT_Send) { CBaseMessage* pMsg = (CBaseMessage*)pPerIOData->pParam; if(pMsg->RemoveRefCount() == 0) CBaseMessage::FreeMsg(pMsg); } else if(pPerIOData->OperationType == SOT_Receive) { m_pDBAllocator->FreeDB((CDataBlock*)pPerIOData->pParam); } CServerClient *pClient = FindClient(lIndexID); if(pClient) { //取消超时监视 if(pClient->IsAccept()) RemoveNewAcceptSocket(pClient->GetIndexID()); pClient->OnClose(); FreeClient(pClient); } FreeIoOper(pPerIOData); }
void RemoveNickFromChannel(char *channel, char *nickname) { struct Channel *cptr; struct Luser *lptr; char *tmp; tmp = channel; if (IsNickPrefix(*tmp)) { if (IsNickPrefix(*(++tmp))) ++tmp; } if (!(cptr = FindChannel(tmp))) return; tmp = GetNick(nickname); if (!(lptr = FindClient(tmp))) return; RemoveFromChannel(cptr, lptr); } /* RemoveNickFromChannel() */
//延时关闭某个客户端 void CClientMgr::DelayCloseClient(int32 clientid) { CClient *cl = FindClient(clientid); if (!cl) return; cl->SetRemove(g_currenttime); }
void ss_process(char *nick, char *command) { int acnt; char **arv; struct Command *sptr; struct Luser *lptr; if (!command || !(lptr = FindClient(nick))) return; if (Network->flags & NET_OFF) { notice(n_StatServ, lptr->nick, "Services are currently \002disabled\002"); return; } acnt = SplitBuf(command, &arv); if (acnt == 0) { MyFree(arv); return; } sptr = GetCommand(statcmds, arv[0]); if (!sptr || (sptr == (struct Command *) -1)) { notice(n_StatServ, lptr->nick, "%s command [%s]", (sptr == (struct Command *) -1) ? "Ambiguous" : "Unknown", arv[0]); MyFree(arv); return; } /* * Check if the command is for admins only - if so, * check if they match an admin O: line. If they do, * check if they are registered with OperServ, * if so, allow the command */ if ((sptr->level == LVL_ADMIN) && !(IsValidAdmin(lptr))) { notice(n_StatServ, lptr->nick, "Unknown command [%s]", arv[0]); MyFree(arv); return; } /* call sptr->func to execute command */ (*sptr->func)(lptr, acnt, arv); MyFree(arv); return; } /* ss_process() */
void RelayMSG(HWND hWnd,clientStruct *clients,SOCKET outSocket) { // This function will relay messages to the designated client(s) BOOLEAN sendAll = FALSE; TCHAR tmpBuffer[BUFFER_SIZE]; clientStruct *tmpClients=clients; clientStruct dataToSend={'\0'}; DisplayError(NULL,TEXT(__FUNCSIG__),0,LOG|WINDOW,NOTICE); // Find the Sender while((tmpClients!=NULL) && (tmpClients->inSocket!=outSocket)) { tmpClients=tmpClients->next; } _tcscpy(dataToSend.nickName,tmpClients->nickName); _tcscpy(dataToSend.sendMSG,tmpClients->sendMSG); _tcscpy(dataToSend.sendTo,tmpClients->sendTo); // Sender not found so leave if(tmpClients==NULL) return; if(_tcscmp(clients->sendTo,TEXT("PUBLIC"))==0) { sendAll=TRUE; StringCbPrintf(tmpBuffer,BUFFER_SIZE,TEXT("Relaying incoming message to %s "),TEXT("all users")); } else StringCbPrintf(tmpBuffer,BUFFER_SIZE,TEXT("Relaying incoming message to %s "),clients->sendTo); DisplayError(NULL,tmpBuffer,0,LOG,NOTICE); // Store sender details if (sendAll) // Send to all except the sender { #pragma warning(suppress: 6303) // Display message in server log window if it's open if(hWnd!=NULL) { StringCbPrintf(tmpBuffer,BUFFER_SIZE,TEXT("Message from %s: %s "),clients->nickName,clients->sendMSG); SendMessage(hWnd,LB_ADDSTRING, 0, (LPARAM)tmpBuffer); } while(tmpClients!=NULL) // Send to all users except the sender { if(tmpClients->inSocket!=outSocket) send(tmpClients->inSocket,(char*)&dataToSend,sizeof(clientStruct),0); tmpClients=tmpClients->next; } } else // Send a single user { clientStruct singleClient = FindClient(clients,clients->sendTo); send(singleClient.inSocket,(char*)&dataToSend,sizeof(clientStruct),0); } }
void CServer::OnDisConn(long lIndexID) { CServerClient* pClient = FindClient(lIndexID); if(pClient) { pClient->ShutDown(); } }
int mythStreamServer::AppendClient(mythBaseClient* client) { SDL_LockMutex(streamservermutex); if (!FindClient(baselist.begin(), baselist.end(), client)) { baselist.push_back(client); } SDL_UnlockMutex(streamservermutex); return 0; }
// --------------------------------------------------------------------------- // Returns the current status of the given session. // --------------------------------------------------------------------------- // MHWRMHapticsObserver::THWRMHapticsStatus CHWRMHapticsCommonData::CurrentStatus( const CSession2* aSession ) const { // get the index of the client TInt index = FindClient( aSession ); return iClientArray[index]->iStatus; }
int TLServer_IP::ClearStocks(CString clientname) { int cid = FindClient(clientname); if (cid==-1) return CLIENTNOTREGISTERED; stocks[cid] = clientstocklist(0); HeartBeat(clientname); D(CString(_T("Cleared stocks for ")+clientname)); return OK; }
bool CTCPServerProxied::OnIncomingData(const std::string &token, const unsigned char *data, size_t bytes_transferred) { CSharedClient *client = FindClient(token); if (client == NULL) { return false; } client->OnIncomingData(data, bytes_transferred); return true; }
/* * es_seennick() * * Give lptr seen info on av[1] nick (exact match) */ static void es_seennick(struct Luser *lptr, int ac, char **av) { aSeen *seen, *recent, *saved = NULL; struct Luser *aptr; if (ac < 2) { notice(n_SeenServ, lptr->nick, "Syntax: SEENNICK <nickname>"); notice(n_SeenServ, lptr->nick, ERR_MORE_INFO, n_SeenServ, "SEENNICK"); return ; } if ((aptr = FindClient(av[1]))) { notice(n_SeenServ, lptr->nick, "%s is on IRC right now!", aptr->nick); return ; } for (seen = seenp; seen; seen = seen->prev) { if (!irccmp(seen->nick, av[1])) { seen->seen = saved; saved = seen; } } if (saved) { recent = saved; for (; saved; saved = saved->seen) { if (saved->time > recent->time) recent = saved; } if (recent->type == 1) { notice(n_SeenServ, lptr->nick, "I last saw %s (%s) %s ago, quiting: %s", recent->nick, recent->userhost, timeago(recent->time, 0), recent->msg); } else if (recent->type == 2) { notice(n_SeenServ, lptr->nick, "I last saw %s (%s) %s ago, changing nicks", recent->nick, recent->userhost, timeago(recent->time, 0)); } } else { notice(n_SeenServ, lptr->nick, "I haven't seen %s recently", av[1]); } } /* es_seennick */
int TLServer_IP::ClearClient(CString clientname) { int cid = FindClient(clientname); if (cid==-1) return CLIENTNOTREGISTERED; client[cid] = ""; stocks[cid] = clientstocklist(0); heart[cid] = NULL; D(CString(_T("Client ")+clientname+_T(" disconnected."))); return OK; }
void CNifManSubConnectionShim::ConnectionLeaving(const CConnection& aConnection) {//destroy a CSubConnectionLinkShimClient belonging to leaving conection TInt i = FindClient(aConnection); if ( i >= 0 ) { CSubConnectionLinkShimClient* client = iShimClients[i]; iShimClients.Remove(i); delete client; } }
// --------------------------------------------------------------------------- // Notifies the given haptics status to the observer identified // with the given session, if the observer message exists. // --------------------------------------------------------------------------- // void CHWRMHapticsCommonData::NotifyStatus( MHWRMHapticsObserver::THWRMHapticsStatus aStatus, const CSession2* aSession ) { // get the index of the observer to be notified TInt index = FindClient( aSession ); // notify observer and store status NotifyStatusToClient( index, aStatus ); }
BOOL MyIOCP::BuildStartFileTransferPackageAndSend(int ClientID) { BOOL bRet=FALSE; m_ContextMapLock.Lock(); ClientContext* pContext = FindClient(ClientID); if (pContext == NULL) return FALSE; bRet= BuildStartFileTransferPackageAndSend(pContext); m_ContextMapLock.Unlock(); return bRet; }
BOOL MyIOCP::BuildFilePackageAndSend(int ClientID,CString sFile) { BOOL bRet=FALSE; m_ContextMapLock.Lock(); ClientContext* pContext = FindClient(ClientID); if (pContext == NULL) return FALSE; bRet=BuildFilePackageAndSend(pContext,sFile); m_ContextMapLock.Unlock(); return bRet; }
//By Luiz45 - Just Return the ChatClient(he will search through CharName) ChatClient* ChatManager::GetChatClient(WCHAR* pCharName){ for (cliIt it = cList.begin(); it != cList.end(); ++it) { if (FindClient(it->second)) { if (wcscmp(it->second->GetCharName(), pCharName) == 0) return it->second; } } return NULL; }
int TLServer_IP::HeartBeat(CString clientname) { int cid = FindClient(clientname); if (cid==-1) return -1; time_t now; time(&now); time_t then = heart[cid]; double dif = difftime(now,then); heart[cid] = now; return (int)dif; }
void CServer::OnSendZeorByte(PER_IO_OPERATION_DATA *pPerIOData,long lIndexID) { if(NULL == pPerIOData) return; FreeIoOper(pPerIOData); CServerClient* pClient = FindClient(lIndexID); if(pClient) { pClient->OnSendZeroByteData(); //继续尝试发送消息 pClient->Send(NULL,0,0); } }
/* * mo_kill - oper message handler * * NOTE: IsPrivileged(sptr), IsAnOper(sptr) == true * IsServer(cptr), IsServer(sptr) == false * * parv[0] = sender prefix * parv[1] = kill victim * parv[parc-1] = kill path */ int mo_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client* victim; char* user; char msg[TOPICLEN + 3]; /* (, ), and \0 */ assert(0 != cptr); assert(0 != sptr); /* * oper connection to this server, cptr is always sptr */ assert(cptr == sptr); assert(IsAnOper(sptr)); if (parc < 3 || EmptyString(parv[parc - 1])) return need_more_params(sptr, "KILL"); user = parv[1]; ircd_snprintf(0, msg, sizeof(msg), "(%.*s)", TOPICLEN, parv[parc - 1]); if (!(victim = FindClient(user))) { /* * If the user has recently changed nick, we automaticly * rewrite the KILL for this new nickname--this keeps * servers in synch when nick change and kill collide */ if (!(victim = get_history(user, (long)15))) return send_reply(sptr, ERR_NOSUCHNICK, user); sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Changed KILL %s into %s", sptr, user, cli_name(victim)); } if (!HasPriv(sptr, MyConnect(victim) ? PRIV_LOCAL_KILL : PRIV_KILL)) return send_reply(sptr, ERR_NOPRIVILEGES); if (IsServer(victim) || IsMe(victim)) { return send_reply(sptr, ERR_CANTKILLSERVER); } /* * if the user is +k, prevent a kill from local user */ if (IsChannelService(victim)) return send_reply(sptr, ERR_ISCHANSERVICE, "KILL", cli_name(victim)); if (!MyConnect(victim) && !HasPriv(sptr, PRIV_KILL)) { sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Nick %s isnt on your server", sptr, cli_name(victim)); return 0; } return do_kill(cptr, sptr, victim, cli_user(sptr)->host, cli_name(sptr), msg); }
int TLServer_IP::RegisterClient(CString clientname) { if (FindClient(clientname)!=-1) return OK; client.push_back(clientname); time_t now; time(&now); heart.push_back(now); // save heartbeat at client index clientstocklist my = clientstocklist(0); stocks.push_back(my); D(CString(_T("Client ")+clientname+_T(" connected."))); return OK; }
// --------------------------------------------------------------------------- // Adds the given message as a haptics status observer. // --------------------------------------------------------------------------- // void CHWRMHapticsCommonData::AddStatusObserver( const RMessage2& aStatusObserverMsg ) { // find the index of the client TInt index = FindClient( aStatusObserverMsg.Session() ); if ( index != KErrNotFound ) { // set new observer message iClientArray[index]->iStatusObserver = aStatusObserverMsg; // read and set request types value THWRMHapticsStatusTypes reqTypes = static_cast<THWRMHapticsStatusTypes>( aStatusObserverMsg.Int0() ); iClientArray[index]->iStatusTypes = reqTypes; // send notification of the current status, if it is needed // for this client if ( iClientArray[index]->iNotificationRequired ) { NotifyStatus( iClientArray[index]->iStatus, aStatusObserverMsg.Session() ); iClientArray[index]->iNotificationRequired = EFalse; } else if ( iClientArray[index]->iRequiredActuators.Count() ) { // there are unsent actuator event notifications, // send immediately THWRMLogicalActuators actuator = iClientArray[index]->iRequiredActuators[0]; // search for the event TInt eventIndex = FindActuatorEvent( actuator ); // send notification, if event found if ( eventIndex != KErrNotFound ) { NotifyActuatorEventToClient( index, iActuatorEvents[eventIndex].iActuatorEvent, iActuatorEvents[eventIndex].iActuator ); } // remove the actuator from required event notification array iClientArray[index]->iRequiredActuators.Remove( 0 ); } } }