예제 #1
0
void ServerModel::NewConnection()
{
    QTcpSocket *sock = new QTcpSocket();
    sock = this->nextPendingConnection();

	m_clients.push_back(sock);

	const QString message = "[" + QTime::currentTime().toString() + "] " + QString("New connection");
	emit SendMessageToMainForm(message);

    connect(sock, SIGNAL(readyRead()), this, SLOT(Read()));
    connect(sock, SIGNAL(disconnected()), this, SLOT(UserDisconnected()));
}
예제 #2
0
bool clsScriptManager::UserConnected(User * u) {
	if(clsSettingManager::mPtr->bBools[SETBOOL_ENABLE_SCRIPTING] == false) {
        return false;
    }

    uint8_t ui8Type = 0; // User
    if(u->i32Profile != -1) {
        if(((u->ui32BoolBits & User::BIT_OPERATOR) == User::BIT_OPERATOR) == false) {
            ui8Type = 1; // Reg
		} else {
			ui8Type = 2; // OP
		}
    }

    bMoved = false;

    int iTop = 0, iTraceback = 0;

    Script * cur = NULL,
        * next = pRunningScriptS;
        
    while(next != NULL) {
    	cur = next;
        next = cur->pNext;

		static const uint32_t iConnectedBits[] = { Script::USERCONNECTED, Script::REGCONNECTED, Script::OPCONNECTED };

		if(((cur->ui16Functions & iConnectedBits[ui8Type]) == iConnectedBits[ui8Type]) == true && (bMoved == false || cur->bProcessed == false)) {
            cur->bProcessed = true;

            lua_pushcfunction(cur->pLUA, ScriptTraceback);
            iTraceback = lua_gettop(cur->pLUA);

            // PPK ... table of connected functions
            static const char* ConnectedFunction[] = { "UserConnected", "RegConnected", "OpConnected" };

            lua_getglobal(cur->pLUA, ConnectedFunction[ui8Type]);
            iTop = lua_gettop(cur->pLUA);
			if(lua_isfunction(cur->pLUA, iTop) == 0) {
				switch(ui8Type) {
					case 0:
						cur->ui16Functions &= ~Script::USERCONNECTED;
						break;
					case 1:
						cur->ui16Functions &= ~Script::REGCONNECTED;
						break;
					case 2:
						cur->ui16Functions &= ~Script::OPCONNECTED;
						break;
				}

                lua_settop(cur->pLUA, 0);
                continue;
            }

            pActualUser = u;

            lua_checkstack(cur->pLUA, 1); // we need 1 empty slots in stack, check it to be sure

			ScriptPushUser(cur->pLUA, u); // usertable

            // 1 passed parameters, zero returned
			if(lua_pcall(cur->pLUA, 1, LUA_MULTRET, iTraceback) != 0) {
                ScriptError(cur);

                lua_settop(cur->pLUA, 0);
                continue;
            }

            pActualUser = NULL;
            
            // check the return value
            // if no return value specified, continue
            // if non-boolean value returned, continue
            // if a boolean true value dwels on the stack, return
        
            iTop = lua_gettop(cur->pLUA);
        
            // no return value
            if(iTop == 0) {
                continue;
            }
        
			if(lua_type(cur->pLUA, iTop) != LUA_TBOOLEAN || lua_toboolean(cur->pLUA, iTop) == 0) {
                lua_settop(cur->pLUA, 0);
                continue;
            }
       
            // clear the stack for sure
            lua_settop(cur->pLUA, 0);

            UserDisconnected(u, cur);

            return true; // means DO NOT process by next scripts
        }
    }

    return false;
}