void JoyPadController::pre_Comm() {
	js_event event;

	bool was_event = false;
	while (!was_event) {
		js_ok_ &= check_Joystick();
		if (!js_ok_) {
			request.add_State_Req(STOP);
			request.add_State_Req(BASE_CONTROL);
			request.add_State_Req(ARM_CONTROL);
			reconntect_Joystick();
			was_event = true;
		} else if (js.get_event(&event)) {

			process_JS_Event(event);

			control(event);
			if (!admin_mode_) {
				base(event);
				arm(event);
			} else
				admin(event);

			if (request.get_State_Req() != 0)
				was_event = true;

		} else {
			boost::this_thread::sleep(boost::posix_time::milliseconds(1));
		}

	}

}
Beispiel #2
0
int main(int argc, char *argv[])
{
    Node root("root");

    Node etc("etc");
    root.add(&etc);
    Leaf hosts("hosts");
    etc.add(&hosts);
    Node apache("apache");
    etc.add(&apache);
    Leaf httpd("httpd.conf");
    apache.add(&httpd);


    Node home("home");
    root.add(&home);
    Node admin("admin");
    home.add(&admin);
    Leaf doc("document.txt");
    admin.add(&doc);

    Node piero("piero");
    home.add(&piero);
    Leaf song("song.mp3");
    piero.add(&song);

    root.dump();
}
Beispiel #3
0
//-----------Admin Portal Menu------------//
int admin_menu()
{
    char choice;
    clrscr();
    gotoxy(29,10);
    textcolor(12);
    cprintf("Please enter your option");
    textcolor(7);
    cout<<"\n\t[1] Proceed to login\n\t[2] Go Back";
    draw_border(6,8,78,15,0);
    gotoxy(29,13);
    cin>>choice;
    switch (choice)
    {
    case '1':
        admin();
        break;
    case '2':
        break;
    default :
        error(1);
        break;
    }
    return 0;
}
Beispiel #4
0
void LoadUserInfoMgr::loadTable(const int iMode)
{
	try{
    #ifdef SHM_FILE_USERINFO
    if(m_pSHMFile->m_poStateData->m_iState[CHANGE_POINT_STATE] != FILE_POINT_STATE){
        Log::log(0,"ERR:请切换为文件资料模式!");
        return;
    }
    #endif
    
	UserInfoAdmin admin(bForce);
	admin.unloadTable(iMode);
	if(admin.cleanOffset(iMode))
	{
		admin.loadTable(iMode);
		admin.bindDataEx(iMode);
	}
	//如果重新加载帐户必须重新加载商品实例相关信息
	if(iMode == ACCT)
	{
		admin.unloadTable(PRODUCT_OFFER_INFO);
		if(admin.cleanOffset(PRODUCT_OFFER_INFO))
		{
			admin.loadTable(PRODUCT_OFFER_INFO);
			admin.bindDataEx(PRODUCT_OFFER_INFO);
		}
	}
	thread_num = 0;
	}catch(...){
		cout<<"单表加载资料出现异常,进程退出!"<<endl;
		throw;
	}
	return;
}
Beispiel #5
0
int main1()
{

	//foo();
	//return 0;



	//RegSetKeySecurity(NULL,NULL,NULL);
	Persona admin(WinBuiltinAdministratorsSid);
	//HKEY hkey;
	//DWORD psdsize = 1;
	LPCTSTR keys[2];
	int num = sizeof(keys) / sizeof(*keys);

	keys[0] =  REG_SCRIPTING;
	keys[1] =  REG_WMI;

	wprintf(L"Administrators group SID: [%s]\n", admin.getSidString());
	wprintf(L"Key: [%s]  Owner: [%s]\n", REG_SCRIPTING, getOwnerString(HKEY_CLASSES_ROOT, REG_SCRIPTING));
	wprintf(L"Key: [%s]  Owner: [%s]\n", REG_WMI, getOwnerString(HKEY_CLASSES_ROOT, REG_WMI));

	TakeOwnership((LPTSTR)REG_SCRIPTING_FULL);
	TakeOwnership((LPTSTR)REG_WMI_FULL);
	TakeOwnershipNoRelection((LPTSTR)REG_WMI_FULL);

	//TakeOwnership(L"HKEY_CLASSES_ROOT\\CLSID\\{730F6CDC-2C86-11D2-8773-92E220524153}");


	TakeOwnership(L"HKEY_CLASSES_ROOT\\CLSID\\AAAAA");
	TakeOwnershipNoRelection(L"HKEY_CLASSES_ROOT\\CLSID\\AAAAA");
	TakeOwnership(L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Elf");
	return 0;
}
Beispiel #6
0
int main(const int argc, const char *argv[])
{
  std::fstream pricesFile(stockfile);
  if (!pricesFile)
    throw std::runtime_error("prices file could not be read");
  auto stock(readStock(pricesFile));
  std::cout << "Read " << stock.size() << " to stock." << std::endl;
  AdminInterface admin(stock, stockfile);
  admin.run();
}
bool QXrdFilePrivate::exists() const {
  XrdClientAdmin admin(qPrintable(this->_fileName.left(this->_fileName.lastIndexOf("/"))));
  if (!admin.Connect())
    return false;
  vecBool vb;
  vecString vs;
  XrdOucString name(qPrintable(this->_fileName.split("//").last().prepend("/")));
  vs.Push_back(name);
  admin.ExistFiles(vs, vb);
  return vb.At(0);
}
Beispiel #8
0
	// --------------------------------------------------------------------
	//
	result_t add(const std::string& hash, const std::string& authname, int level)
	{
		access::s_access_level* accessLevel = 0;

		if (admin::find_admin_by_hash(hash, NULL)) return E_HASH_INUSE;
		if (admin::find_admin_by_name(authname, NULL)) return E_NAME_INUSE;		
		if (!access::find(level, &accessLevel)) return E_LEVEL_NOT_EXIST;

		admin::s_admin admin(authname, hash, *accessLevel);
		admin::add(admin);
		return E_OK;
	}
Beispiel #9
0
void LoadUserInfoMgr::unLoad()
{
	try{
        #ifdef SHM_FILE_USERINFO
        if(m_pSHMFile->m_poStateData->m_iState[CHANGE_POINT_STATE] != FILE_POINT_STATE){
            Log::log(0,"ERR:请切换为文件资料模式!");
            return;
        }
        #endif
        
		UserInfoAdmin admin(bForce);
		admin.unload();
	}catch(...){
		cout<<"卸载用户资料共享内存出现异常,进程退出"<<endl;
		throw;
	}
	return;
}
Beispiel #10
0
void LoadUserInfoMgr::loadAll()
{
	try{
		UserInfoAdmin admin(bForce);
        
        #ifdef SHM_FILE_USERINFO
        if(m_pSHMFile->m_poStateData->m_iState[CHANGE_POINT_STATE] != FILE_POINT_STATE){
            Log::log(0,"ERR:请切换为文件资料模式!");
            return;
        }
        #endif
        
		admin.load();
	}catch(...){
		cout<<"串行加载所有资料发生异常,进程退出!"<<endl;
		throw;
	}
	return;
}
Beispiel #11
0
int main()
{
	int flag = login();
	while(1)
	{
		switch(flag)
		{
			//0表示子菜单的程序全部正常退出,保存之前修改的信息,再重新登陆。
			case 0:flag = login();break;
			case 1:flag = user();break;//进入用户登陆界面
			case 2:flag = add_user();break;//进入新用户注册界面
			case 3:flag = admin();break;//管理员登陆界面
			case 4:return 0;
			case -2:return 0;//子菜单直接退出程序
			case -1:flag = 0;break;
			default:printf("error menu return message\n");return 0;
		}
	}
	return 0;
}
Beispiel #12
0
int main(int argc, char** argv)
{
    #ifdef Log_KEYS
        fprintf(stderr, "Log_LEVEL = KEYS, EXPECT TO SEE PRIVATE KEYS IN YOUR LOGS!\n");
    #endif
    Crypto_init();
    assert(argc > 0);

    if (argc == 1) { // no arguments
        if (isatty(STDIN_FILENO)) {
            // We were started from a terminal
            // The chances an user wants to type in a configuration
            // bij hand are pretty slim so we show him the usage
            return usage(argv[0]);
        } else {
            // We assume stdin is a configuration file and that we should
            // start routing
        }
    }
    if (argc == 2) { // one argument
        if (strcmp(argv[1], "--help") == 0) {
            return usage(argv[0]);
        } else if (strcmp(argv[1], "--genconf") == 0) {
            return genconf();
        } else if (strcmp(argv[1], "--getcmds") == 0) {
            // Performed after reading the configuration
        } else if (strcmp(argv[1], "--pidfile") == 0) {
            // Performed after reading the configuration
        } else {
            fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[1]);
        fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
            return -1;
        }
    }
    if (argc >  2) { // more than one argument?
        fprintf(stderr, "%s: too many arguments\n", argv[0]);
        fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
        return -1;
    }

    struct Context context;
    memset(&context, 0, sizeof(struct Context));
    context.base = event_base_new();

    // Allow it to allocate 4MB
    context.allocator = MallocAllocator_new(1<<22);
    struct Reader* reader = FileReader_new(stdin, context.allocator);
    Dict config;
    if (JsonBencSerializer_get()->parseDictionary(reader, context.allocator, &config)) {
        fprintf(stderr, "Failed to parse configuration.\n");
        return -1;
    }

    if (argc == 2 && strcmp(argv[1], "--getcmds") == 0) {
        return getcmds(&config);
    }
    if (argc == 2 && strcmp(argv[1], "--pidfile") == 0) {
        pidfile(&config);
        return 0;
    }

    char* user = setUser(Dict_getList(&config, BSTR("security")));

    // Admin
    Dict* adminConf = Dict_getDict(&config, BSTR("admin"));
    if (adminConf) {
        admin(adminConf, user, &context);
    }

    // Logging
    struct Writer* logwriter = FileWriter_new(stdout, context.allocator);
    struct Log logger = { .writer = logwriter };
    context.logger = &logger;

    struct Address myAddr;
    uint8_t privateKey[32];
    parsePrivateKey(&config, &myAddr, privateKey);

    context.eHandler = AbortHandler_INSTANCE;
    context.switchCore = SwitchCore_new(context.logger, context.allocator);
    context.ca =
        CryptoAuth_new(&config, context.allocator, privateKey, context.base, context.logger);
    context.registry = DHTModules_new(context.allocator);
    ReplyModule_register(context.registry, context.allocator);

    // Router
    Dict* routerConf = Dict_getDict(&config, BSTR("router"));
    registerRouter(routerConf, myAddr.key, &context);

    SerializationModule_register(context.registry, context.allocator);

    // Authed passwords.
    List* authedPasswords = Dict_getList(&config, BSTR("authorizedPasswords"));
    if (authedPasswords) {
        authorizedPasswords(authedPasswords, &context);
    }

    // Interfaces.
    Dict* interfaces = Dict_getDict(&config, BSTR("interfaces"));
    Dict* udpConf = Dict_getDict(interfaces, BSTR("UDPInterface"));

    if (udpConf) {
        configureUDP(udpConf, &context);
    }

    if (udpConf == NULL) {
        fprintf(stderr, "No interfaces configured to connect to.\n");
        return -1;
    }

    // pid file
    String* pidFile = Dict_getString(&config, BSTR("pidFile"));
    if (pidFile) {
        Log_info1(context.logger, "Writing pid of process to [%s].\n", pidFile->bytes);
        FILE* pf = fopen(pidFile->bytes, "w");
        if (!pf) {
            Log_critical2(context.logger,
                          "Failed to open pid file [%s] for writing, errno=%d\n",
                          pidFile->bytes,
                          errno);
            return -1;
        }
        fprintf(pf, "%d", getpid());
        fclose(pf);
    }

    Ducttape_register(&config,
                      privateKey,
                      context.registry,
                      context.routerModule,
                      context.routerIf,
                      context.switchCore,
                      context.base,
                      context.allocator,
                      context.logger);

    uint8_t address[53];
    Base32_encode(address, 53, myAddr.key, 32);
    Log_info1(context.logger, "Your address is: %s.k\n", address);
    uint8_t myIp[40];
    Address_printIp(myIp, &myAddr);
    Log_info1(context.logger, "Your IPv6 address is: %s\n", myIp);

    // Security.
    security(Dict_getList(&config, BSTR("security")), context.logger, context.eHandler);

    event_base_loop(context.base, 0);

    // Never reached.
    return 0;
}
Beispiel #13
0
LoginWindow::LoginWindow(QWidget* parent):QFrame(parent){
    setAttribute(Qt::WA_DeleteOnClose,true);
    setStyleSheet(GUIStyle::generalStyle()+"QLabel{font-weight:bold;} QPushButton{font-weight:bold;}");
    setWindowIcon(QIcon(GUIStyle::iconPath()));
    setMinimumSize(800,450);
    setMaximumSize(800,450);
    mainVerticalLayout=new QVBoxLayout();
    //immagine
    lImage=new QLabel;
    GUIStyle::initLogo(lImage,785,250);
    mainVerticalLayout->addWidget(lImage,0,Qt::AlignHCenter);

    //form di login
    loginLayout=new QHBoxLayout();
    loginLayout->setContentsMargins(0,50,0,10);
    //username
    vlUsername=new QVBoxLayout();
    lUsername=new QLabel("Username");
    lUsername->setAlignment(Qt::AlignCenter);
    vlUsername->addWidget(lUsername,0,Qt::AlignHCenter|Qt::AlignVCenter);
    teUsername=new QLineEdit;
    vlUsername->addWidget(teUsername,0,Qt::AlignHCenter|Qt::AlignVCenter);
    loginLayout->addLayout(vlUsername);
    //password
    vlPwd=new QVBoxLayout();
    lPwd=new QLabel("Password:"******"Login");
    loginButton->setCursor(QCursor(Qt::PointingHandCursor));
    mainVerticalLayout->addWidget(loginButton,0,Qt::AlignHCenter|Qt::AlignVCenter);
    //etichetta errore
    lError=new QLabel;
    lError->setHidden(true);
    lError->setAlignment(Qt::AlignCenter);
    lError->resize(150,25);
    lError->setStyleSheet(GUIStyle::errorLabelStyle());
    mainVerticalLayout->addWidget(lError,0,Qt::AlignHCenter|Qt::AlignVCenter);
    //login come admin
    adminButton=new QPushButton("Login come Admin");
    adminButton->setCursor(QCursor(Qt::PointingHandCursor));
    adminButton->setFlat(true);
    mainVerticalLayout->addWidget(adminButton,0,Qt::AlignRight);
    setLayout(mainVerticalLayout);
    setWindowTitle("LinQedIn");
    tePwd->setPlaceholderText("Password");
    teUsername->setPlaceholderText("Username");
    teUsername->setFocus();

    QShortcut *quit=new QShortcut(QKeySequence("Ctrl+Q"),this),
            *admin=new QShortcut(QKeySequence("Ctrl+D"),this);

    //segnali e slots
    connect(teUsername,SIGNAL(returnPressed()),this,SLOT(login()));
    connect(tePwd,SIGNAL(returnPressed()),this,SLOT(login()));
    connect(loginButton,SIGNAL(clicked()),this,SLOT(login()));
    connect(adminButton,SIGNAL(clicked()),this,SLOT(admin()));
    connect(quit,SIGNAL(activated()),this,SLOT(close()));
    connect(admin,SIGNAL(activated()),this,SLOT(admin()));
}//LoginWindow
PlayersWindow::PlayersWindow(QWidget *parent, int expireDays)
    : QWidget (parent)
{
    setAttribute(Qt::WA_DeleteOnClose, true);
    resize(726, this->height());

    QGridLayout *mylayout = new QGridLayout(this);

    const auto &members = SecurityManager::getMembers();

    mytable = new QCompactTable(members.size(),7);

    mytable->setShowGrid(true);
    mylayout->addWidget(mytable,0,0,1,6);

    QMap<int, QString> authgrade;
    authgrade[0] = "User";
    authgrade[1] = "Mod";
    authgrade[2] = "Admin";
    authgrade[3] = "Owner";

    QStringList headers;
    headers << "Player" << "Authority" << "Banned Status" << "Registered" << "IP" << "Last Appearance" << "Expires In";
    mytable->setHorizontalHeaderLabels(headers);

    int i = 0;

    for (auto it = members.begin(); it != members.end(); ++it) {
        const SecurityManager::Member &m = it->second;

        QTableWidgetItem *witem = new QTableWidgetItem(m.name);
        mytable->setItem(i, 0, witem);

        witem = new QTableWidgetItem(authgrade[m.authority()]);
        mytable->setItem(i, 1, witem);

        QString bannedString = "Banned";
        int expiration = m.ban_expire_time - QDateTime::currentDateTimeUtc().toTime_t();
        if(expiration < 0) {
            if (m.ban_expire_time != 0)
            bannedString = "Expires on Login";
        } else {
            if(expiration < 60) {
                if(expiration == 1) {
                    bannedString.append(QString(" (%1 second)").arg(expiration));
                } else {
                    bannedString.append(QString(" (%2 seconds)").arg(expiration));
                }
            } else {
                if(expiration >= 60) {
                    expiration = expiration / 60;
                    if(expiration == 1) {
                        bannedString.append(QString(" (%1 minute)").arg(expiration));
                    } else {
                        bannedString.append(QString(" (%2 minutes)").arg(expiration));
                    }
                }
            }
        }
        witem = new QTableWidgetItem(m.banned ? bannedString : "Fine");
        mytable->setItem(i, 2, witem);

        witem = new QTableWidgetItem(m.isProtected() > 0 ? "Yes" : "No");
        mytable->setItem(i, 3, witem);

        witem = new QTableWidgetItem(m.ip);
        mytable->setItem(i, 4, witem);

        witem = new QTableWidgetItem(m.date);
        mytable->setItem(i, 5, witem);

        witem = new QTableWidgetItem(QString::number(expireDays - QDate::fromString(m.date, Qt::ISODate).daysTo(QDate::currentDate())) + " Days");
        mytable->setItem(i, 6, witem);

        i++;
    }

    //mytable->sortByColumn(0, Qt::AscendingOrder);

    //mytable->setSortingEnabled(true);

    QPushButton *_authority = new QPushButton(tr("&Authority"));
    QMenu *m = new QMenu(_authority);
    m->addAction(tr("User"), this, SLOT(user()));
    m->addAction(tr("Moderator"), this, SLOT(mod()));
    m->addAction(tr("Administrator"), this, SLOT(admin()));
    m->addAction(tr("Owner"), this, SLOT(owner()));
    _authority->setMenu(m);

    QPushButton *_ban = new QPushButton(tr("&Ban"));
    QPushButton *_unban = new QPushButton(tr("U&nban"));
    QPushButton *_clpass = new QPushButton(tr("&Clear Password"));
    QCheckBox *enableSorting = new QCheckBox(tr("&Enable sorting"));

    mylayout->addWidget(_authority,1,0);
    mylayout->addWidget(_ban,1,2);
    mylayout->addWidget(_unban,1,3);
    mylayout->addWidget(_clpass,1,4);
    mylayout->addWidget(enableSorting, 1, 5);

    if (mytable->rowCount() == 0)
        return;

    connect(_ban,SIGNAL(clicked()),SLOT(ban()));
    connect(_unban,SIGNAL(clicked()),SLOT(unban()));
    connect(_clpass,SIGNAL(clicked()),SLOT(clpass()));
    connect(enableSorting, SIGNAL(toggled(bool)), SLOT(enableSorting(bool)));
}
PlayersWindow::PlayersWindow(QWidget *parent, int expireDays)
    : QWidget (parent)
{
    setAttribute(Qt::WA_DeleteOnClose, true);
    resize(726, this->height());

    QGridLayout *mylayout = new QGridLayout(this);

    mytable = new QCompactTable(0,7);

    mytable->setShowGrid(true);
    mylayout->addWidget(mytable,0,0,1,6);

    QMap<int, QString> authgrade;
    authgrade[0] = "User";
    authgrade[1] = "Mod";
    authgrade[2] = "Admin";
    authgrade[3] = "Owner";

    QStringList headers;
    headers << "Player" << "Authority" << "Banned Status" << "Registered" << "IP" << "Last Appearance" << "Expires In";
    mytable->setHorizontalHeaderLabels(headers);

    QSqlQuery q;
    q.setForwardOnly(true);

    q.exec("select count(*) from trainers");

    if (q.next()) {
        mytable->setRowCount(q.value(0).toInt());
    }

    q.exec("select name, auth, banned, hash, ip, laston, ban_expire_time from trainers order by name asc");

    int i = 0;

    while(q.next()) {
        QTableWidgetItem *witem = new QTableWidgetItem(q.value(0).toString());
        mytable->setItem(i, 0, witem);

        witem = new QTableWidgetItem(authgrade[q.value(1).toInt()]);
        mytable->setItem(i, 1, witem);

        QString bannedString = "Banned";
        int expiration = q.value(6).toInt() - QDateTime::currentDateTimeUtc().toTime_t();
        if(expiration < 0) {
            if (q.value(6).toInt() != 0)
            bannedString = "Expires on Login";
        } else {
            if(expiration < 60) {
                if(expiration == 1) {
                    bannedString.append(QString(" (%1 second)").arg(expiration));
                } else {
                    bannedString.append(QString(" (%2 seconds)").arg(expiration));
                }
            } else {
                if(expiration >= 60) {
                    expiration = expiration / 60;
                    if(expiration == 1) {
                        bannedString.append(QString(" (%1 minute)").arg(expiration));
                    } else {
                        bannedString.append(QString(" (%2 minutes)").arg(expiration));
                    }
                }
            }
        }
        witem = new QTableWidgetItem(q.value(2).toBool() ? bannedString : "Fine");
        mytable->setItem(i, 2, witem);

        witem = new QTableWidgetItem(q.value(3).toString().length() > 0 ? "Yes" : "No");
        mytable->setItem(i, 3, witem);

        witem = new QTableWidgetItem(q.value(4).toString());
        mytable->setItem(i, 4, witem);

        witem = new QTableWidgetItem(q.value(5).toString());
        mytable->setItem(i, 5, witem);

        witem = new QTableWidgetItem(QString::number(expireDays - QDate::fromString(q.value(5).toString(), "yyyy-MM-dd").daysTo(QDate::currentDate())) + " Days");
        mytable->setItem(i, 6, witem);

        i++;
    }

    mytable->sortByColumn(0, Qt::AscendingOrder);

    mytable->setSortingEnabled(true);

    QPushButton *_authority = new QPushButton(tr("&Authority"));
    QMenu *m = new QMenu(_authority);
    m->addAction(tr("User"), this, SLOT(user()));
    m->addAction(tr("Moderator"), this, SLOT(mod()));
    m->addAction(tr("Administrator"), this, SLOT(admin()));
    m->addAction(tr("Owner"), this, SLOT(owner()));
    _authority->setMenu(m);

    QPushButton *_ban = new QPushButton(tr("&Ban"));
    QPushButton *_unban = new QPushButton(tr("U&nban"));
    QPushButton *_clpass = new QPushButton(tr("&Clear Password"));

    mylayout->addWidget(_authority,1,0);
    mylayout->addWidget(_ban,1,2);
    mylayout->addWidget(_unban,1,3);
    mylayout->addWidget(_clpass,1,4);

    if (mytable->rowCount() == 0)
        return;

    connect(_ban,SIGNAL(clicked()),SLOT(ban()));
    connect(_unban,SIGNAL(clicked()),SLOT(unban()));
    connect(_clpass,SIGNAL(clicked()),SLOT(clpass()));
}
void addteacher()
{
     clrscr();system("cls");
     char cond[]="yes";char op2[3]; int mob,mobp;      int i,y,flag,display,lm;char numb[10];

      FILE *p,*q;
      int q1,nl,tch=0;char q2[30];char initial[2];char acline[80];int yoe,pos=0;
      p = fopen("teacher.txt","a+");

      while (!feof(p))
       {
          for(nl=0;nl<80;nl++)
          acline[nl]=NULL;
          fgets(acline,80,p);
          if(!(strlen(acline)>10)) { pos=1; }
          else {tch=tch+1;}
       }


     textcolor(14);printf("\nYou can add ");textcolor(12);printf("%d",20-tch);textcolor(14);printf(" teachers more ");textcolor(11);printf(" [Max. limit is 20 teachers]\n");
     textcolor(10);printf("\nDo you want to add more Teacher ?");textcolor(13);printf(" (yes/no)\n");
     textcolor(15);
     fflush(stdin);
     gets(op2);
     if(!strcmp(op2,cond))
     {

        /* FILE *p;
         int q1,nl,tch=0;char q2[30];char initial[2];char acline[80];int yoe,pos=0;
         p = fopen("teacher.txt","a+");

                       while (!feof(p))
                       {
                           for(nl=0;nl<80;nl++)
                           acline[nl]=NULL;
                           fgets(acline,80,p);
                           if(!(strlen(acline)>10)) { pos=1; }
                           else {tch=tch+1;}
                       }*/

         do
         {
             if(tch>=20){ textcolor(9);printf("\nYou cannot add more teacher , delete some old teachers to add new teachers\n");fclose(p);textcolor(15);printf("\nPress any key to return to Admin menu");getch();admin(); }
             tch=tch+1;clrscr();system("cls");
             flag=2;
             for(mob=0;mob<2;)
             {
                mobp=wherey();textcolor(12);printf("\nEnter Teacher's Name\n");
                yoo:
                  {
                     gotoxy(1,mobp+2);textcolor(15);
                     fflush(stdin);
                     gets(q2);
                     if((strlen(q2)>=4)&&(strlen(q2)<30))
                     {break;}
                     else
                     {   textcolor(11);printf("Please enter your valid name\n");textcolor(10);printf("Name must contain more than 4 & less than 30 characters after 3 seconds");Sleep(3900);
                         gotoxy(1,mobp+2);
                         textcolor(0);printf("____________________________________________________________________________________");
                         gotoxy(1,mobp+3);printf("____________________________________________________________________________________");
                         gotoxy(1,mobp+4);printf("____________________________________________________________________________________");
                         goto yoo;
                     }
                  }
             }

              if(pos==1)
              { fprintf(p,"!%s!",q2); pos=0;}
              else
              { fprintf(p,"\n!%s!",q2);}
              fflush(stdin);
              for(q1=0;q1<strlen(q2);q1++)
              {
                  initial[0]=q2[0];
                  if(q2[q1]==' ')
                  {
                     initial[1]=q2[q1+1];
                     initial[2]='\0';
                     break;
                  }
                  else
                  {
                      initial[1]='\0';
                  }
              }
//               printf("Initial is %s \n",initial);
             fprintf(p,"%s!",initial);
             fflush(stdin);
             textcolor(12);printf("Enter Teacher's Qualifications\n");textcolor(15);
             fflush(stdin);
             gets(q2);
             fprintf(p,"%s!",q2);
             for(mob=0;mob<2;)
             {
                mobp=wherey();textcolor(12);printf("Enter Teacher's year of experience (0-30)\n");
                yoi:
                  {
                     gotoxy(1,mobp+1);textcolor(15);
                     fflush(stdin);
                     scanf("%d",&yoe);
                     if((yoe>=0)&&(yoe<31)) {break;}
                     else
                     {   textcolor(11);printf("Please enter valid teacher's year of experience number after 3 seconds");Sleep(2600);
                         gotoxy(1,mobp+1);
                         textcolor(0);printf("__________________________________________________________________________\n");
                         printf("__________________________________________________________________________\n");
                         goto yoi;
                     }
                  }
             }
             fprintf(p,"%d!",yoe);
             fflush(stdin);

             mobp=wherey();textcolor(12);printf("Enter Teacher's Mobile number(id) [Should be of 10 digits]\n");
             mb:
              {
                 gotoxy(1,mobp+1);textcolor(15);
                 fflush(stdin);
                 gets(q2);
                 fflush(stdin);
                 if(!(strlen(q2)==10))
                 {
                     textcolor(11);printf("Please enter 10 digit mobile number after 2 seconds");Sleep(2000);
                     gotoxy(1,mobp+1);
                     textcolor(0);printf("__________________________________________________________________________\n");
                     printf("__________________________________________________________________________\n");
                     goto mb;
                 }
                 else
                 {
                     q=fopen("teacher.txt","r");
                     for(lm=1;lm!=tch;lm++)
                     {
                         i=0;//printf("\n\n\n\n\n%d %d",lm,tch);
                         for(nl=0;nl<80;nl++)
                         acline[nl]=NULL;
                         for(nl=0;nl<10;nl++)
                         numb[nl]=NULL;
                         fgets(acline,80,q);
                         if(!(strlen(acline)>10)) { }
                         else {for(display=0;acline[display]!=0;display++)
                         {
                              if(acline[display]=='!')
                              {i=i+1;}

                              if(i==5){for(y=0;y<10;y++){numb[y]=acline[display+1+y];numb[10]='\0';}if(!(strcmp(q2,numb))){textcolor(11);printf("Please enter correct(unique) 10 digit mobile number after 2 seconds");Sleep(2000);
                     gotoxy(1,mobp+1);
                     textcolor(0);printf("__________________________________________________________________________\n");
                     printf("__________________________________________________________________________\n");
                     goto mb;}else{}}
                         }}
                     }
                     fclose(q);
                 }
              }

             fprintf(p,"%s!",q2);
             fflush(stdin);fflush(p);
             textcolor(14);printf("\nYou can add ");textcolor(12);printf("%d",20-tch);textcolor(14);printf(" teachers more ");textcolor(11);printf(" [Max. limit is 20 teachers]\n");
             textcolor(10);printf("\nDo you want to add more Teacher ?");textcolor(13);printf(" (yes/no)\n");textcolor(15);
             gets(q2);
         }while((!strcmp(q2,cond))&&(tch<=20));
           fclose(p);
           //if(tch==20){ textcolor(9);printf("\nYou cannot add more teacher , delete some old teachers to add new teachers\n"); }
     }
   fclose(p);textcolor(15);printf("\nPress any key to return to Admin menu");
   getch();
   admin();
}
Beispiel #17
0
/* Main: startup until working state, loop */
int main(int argc, char *argv[])
{
	Gurucore *core;
	Guru *guru;
	char *opthost = NULL, *optname = NULL, *optdatadir = NULL;
	char *input;
	int language;
	int ret;

	/* Recognize command line arguments */
	struct option options[] =
	{
		{"help", no_argument, 0, 'h'},
		{"specs", no_argument, 0, 's'},
		{"version", no_argument, 0, 'v'},
		{"name", required_argument, 0, 'n'},
		{"host", required_argument, 0, 'H'},
		{"datadir", required_argument, 0, 'd'},
		{0, 0, 0, 0}
	};
	int optindex;
	int opt;

	extern int _nl_msg_cat_cntr;

	signal(SIGTERM, sighandler);

	bindtextdomain("grubby", PREFIX "/share/locale");
	textdomain("grubby");
	setlocale(LC_ALL, "");

	setenv("LANGUAGE", getenv("LANG"), 1);
	++_nl_msg_cat_cntr;

	while(1)
	{
		opt = getopt_long(argc, argv, "hsvH:n:d:", options, &optindex);
		if(opt == -1) break;
		switch(opt)
		{
			case 'h':
				printf(_("Grubby - the GGZ Gaming Zone Chat Bot\n"));
				printf(_("Copyright (C) 2001 - 2006 Josef Spillner, [email protected]\n"));
				printf(_("Published under the terms of the GNU GPL\n\n"));
				printf(_("Recognized options:\n"));
				printf(_("[-h | --help   ]: Show this help screen\n"));
				printf(_("[-H | --host   ]: Connect to this host\n"));
				printf(_("[-n | --name   ]: Use this name\n"));
				printf(_("[-d | --datadir]: Use this GGZ data directory (default: ~/.ggz)\n"));
				printf(_("[-s | --specs  ]: Display compilation options\n"));
				printf(_("[-v | --version]: Display version number\n"));
				exit(0);
				break;
			case 'H':
				opthost = optarg;
				break;
			case 'n':
				optname = optarg;
				break;
			case 'v':
				printf(_("Grubby version %s\n"), GRUBBY_VERSION);
				exit(0);
				break;
			case 's':
				printf("Grubby specifications:\n");
				printf("- network core plugins: %s%s%s%s\n",
					"[console]",
					"[irc]",
					"[ggz]",
#ifdef HAVE_SILC
					"[silc]"
#else
					""
#endif
					);
				printf("- data directory: %s\n", GRUBBYDIR);
				printf("- embeddable scripts:\n");
#ifdef EMBED_RUBY
				printf("  ruby   [%s]\n", /*RUBY_VERSION*/"???");
#endif
#ifdef EMBED_PERL
				printf("  perl   [%i.%i.%i]\n", PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
#endif
#ifdef EMBED_PYTHON
				printf("  python [%s]\n", PY_VERSION);
#endif
#ifdef EMBED_TCL
				printf("  tcl    [%s]\n", TCL_PATCH_LEVEL);
#endif
#ifdef EMBED_PHP
				printf("  php    [%s]\n", "???");
#endif
				exit(0);
				break;
			case 'd':
				optdatadir = optarg;
				break;
			default:
				printf(_("Unknown command line option, try --help.\n"));
				exit(-1);
				break;
		}
	}

	/* Bring grubby to life */
	printf(_("Grubby: initializing...\n"));
	core = guru_init(optdatadir);
	if(!core)
	{
		printf(_("Grubby initialization failed!\n"));
		printf(_("Check if the bot is configured properly using grubby-config.\n"));
		exit(-1);
	}

	/* Apply command line options */
	if(opthost) core->host = opthost;
	if(optname) core->name = optname;
	if(optdatadir) core->datadir = optdatadir;

	/* Start connection procedure */
	printf(_("Grubby: connect to %s...\n"), core->host);
	(core->net_log)(core->logfile);
	(core->net_connect)(core->host, 5688, core->name, core->password);
	if(core->i18n_init) (core->i18n_init)(core->language, getenv("LANG"));

	/* Main loop */
	running = 1;
	while(running)
	{
		/* Permanently check states */
		switch((core->net_status)())
		{
			case NET_ERROR:
				printf(_("ERROR: Couldn't connect\n"));
				exit(-1);
				break;
			case NET_LOGIN:
				printf(_("Grubby: Logged in.\n"));
				(core->net_join)(core->autojoin);
				break;
			case NET_GOTREADY:
				printf(_("Grubby: Ready.\n"));
				break;
			case NET_INPUT:
				guru = (core->net_input)();
				guru->guru = core->name;
				guru->datadir = core->datadir;

				if(core->i18n_catalog) (core->i18n_catalog)(1);
				if(core->i18n_check) (core->i18n_check)(guru->player, "", 1);
				ret = admin(guru, core);
				if(core->i18n_catalog) (core->i18n_catalog)(0);

				if(!ret)
				{
					/* If message is valid, try to translate it first */
					language = 0;
					if(guru->type == GURU_PRIVMSG) language = 1;
					else if(guru->type == GURU_DIRECT) language = 1;

					input = NULL;
					if(core->i18n_check)
					{
						(core->i18n_catalog)(1);
						input = (core->i18n_check)(guru->player, guru->message, language);
						(core->i18n_catalog)(0);

						if(input)
						{
							ggz_free(guru->message);
							guru->message = input;
							/*guru->message = (core->i18n_translate)(guru->player, guru->message);*/
							(core->net_output)(guru);
						}
					}
					if(!input)
					{
						if(core->i18n_catalog) (core->i18n_catalog)(1);
						if(core->i18n_check) (core->i18n_check)(guru->player, "", language);
						guru = guru_work(guru);
						if(core->i18n_catalog) (core->i18n_catalog)(0);

						if(guru)
						{
							/*if(core->i18n_translate)
								guru->message = (core->i18n_translate)(guru->player, guru->message);*/
							(core->net_output)(guru);
						}
					}
				}
				break;
		}
	}

	/* Shutdown the bot properly */
	return guru_close(core);
}