Example #1
0
void menu(int new_sockfd, char buffer[])
{
	int choice;
	recv(new_sockfd,buffer, bufsize,0);
	choice = atoi(buffer);
	switch(choice)
	{
		case 1:
		load_password();
		login(new_sockfd);
		break;
		case 2:
		signup(new_sockfd,buffer);
		menu(new_sockfd, buffer);
		break;
case 3:
roster();
break;
		case 4:
		printf("\n\n\nClient disconnected from server...");
		exit(0);
		break;
		default:
		menu(new_sockfd, buffer);
		break;
	}
}
Example #2
0
/*Di bawah ini fungsi untuk print perintah ke user. Kalo bikin fungsi lagi, di atasnya aja ya...*/
void Client::printSignUp()
{
    cout << "Welcome to this chat application" << endl;
    cout << "Masukkan username baru\t: ";
    getline(cin, username);
    cout << "Masukkan password\t\t: ";
    getline(cin, password);
    cout << "Konfirmasi Password\t: ";
    getline (cin, confirmPassword);
    
    if(password.compare(confirmPassword) == 0)
    {
        char * buff; buff = new char[MAXBUF];
    
        strcpy(buff,signup(username, password));
        cout << (string)buff << endl;
        openTCPConnection();
        setServerAddress((char*)"127.0.0.1");
        reqConnect();
        ConnectionHandler(buff);
    }
    else
    {
        cout << "Password dan konfirmasi password anda tidak sama" << endl;
    }

}
Example #3
0
void Client::setup(const QString &setup_str){
    if(socket && !socket->isConnected())
        return;

    if(ServerInfo.parse(setup_str)){
        signup();
        emit server_connected();
    }else{
        QMessageBox::warning(NULL, tr("Warning"), tr("Setup string can not be parsed: %1").arg(setup_str));
    }
}
Example #4
0
void MMD()
{   
    cout << "SmallOS by <you will know who, if you sign in and type ""about""." << endl;
	cout << "1. Sign up" << endl;
	cout << "2. Sign in" << endl;
    cout << "3. Shutdown guest" << endl;
	
	cout << "Enter your choise: ";
	int choise = 0;
	cin >> choise;
	switch (choise)
	{
	case 1: signup();break;
	case 2: signin();break;
	case 3: exit(0);break;
	default : MMD();break;
	}

}
Example #5
0
int main()
{   
    initwindow(1275,700);
    setfillstyle(1,1);
    floodfill(100,100,1);
    
    setcolor(12);
    setbkcolor(1);
    settextstyle(0,0,8);
    outtextxy(330,160,"WELCOME TO ");
    outtextxy(140,270,"THE V-PLAY STORE");
    
    setcolor(7);
    rectangle(140,450,440,550);
    rectangle(840,450,1140,550);
    setfillstyle(1,7);
    floodfill(300,500,7);
    setfillstyle(1,7);
    floodfill(950,500,7);
    settextstyle(0,0,4);
    setcolor(0);
    setbkcolor(7);
    outtextxy(170,480,"Sign Up!");
    outtextxy(875,480,"Sign In");
    
    
    int x = getmaxx( );
    int y = getmaxy( );
    setmousequeuestatus(WM_LBUTTONDOWN);
    while(!ismouseclick(WM_LBUTTONDOWN));
    {
                                        getmouseclick(WM_LBUTTONDOWN,x,y);
                                        if((x>840 && x<1140) && (y>450 && y<550))
                                        login();
                                        else if((x>140 && x<440) && (y>450 && y<550))
                                        signup();
    }
    system("pause");
    return 0;
}
Example #6
0
void start(){
	string str; 
	bool correct;
	correct = false;
	while (!correct){
		cout << endl << ">  ";
		cin >> str;
		if(str.compare("signup")==0){
			signup();
		}
		else if(str.compare("login")==0){
			login();
		}
		else if(str.compare("exit")==0){
			correct=true;
			active = false;
			closeConnection();
			exit(0);
		}
		else {
			cout << "Wrong input!" <<endl<<endl;
		}
	}
}
Example #7
0
void LoginWidget::displayButton()
{
  QPushButton *signupButton = new QPushButton(tr("Sign Up"), this);
  QPushButton *displayIP = new QPushButton(tr("Expert mode"), this);

  displayIP->setStyleSheet("background-color: #1DAEF1");
  _buttons->addButton(QDialogButtonBox::Ok);
  _buttons->addButton(QDialogButtonBox::Cancel);
  _buttons->addButton(displayIP, QDialogButtonBox::ActionRole);
  _buttons->addButton(signupButton, QDialogButtonBox::ActionRole);
  _buttons->button(QDialogButtonBox::Ok)->setText(tr("Login"));
  _buttons->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));

  connect(_buttons->button(QDialogButtonBox::Cancel), SIGNAL(released()),
	  this, SLOT(close()));
  connect(_buttons->button(QDialogButtonBox::Ok), SIGNAL(released()),
	  this, SLOT(checkLogin()));
  connect(signupButton, SIGNAL(released()),
	  this, SLOT(signup()));
  connect(displayIP, SIGNAL(released()),
	  this, SLOT(displayIPFunction()));

  _mainLayout->addWidget(_buttons, 3, 0, 1, 2);
}
void tweet_server(void *q)
{

    char *request, *reply, *format, *query;
    th_args_dt *args = (th_args_dt *)q;

    tweet_req_dt *tweet_req = (tweet_req_dt *)malloc(sizeof(tweet_req_dt));

    tweet_resp_dt *result;
    /*receive buffer*/
    pthread_mutex_lock(&args->th_mutex);
    request = recv_buf(args->sock);
    pthread_mutex_unlock(&args->th_mutex);
    printf("Request received: %s\n",request);

    char *dup = (char *)malloc(strlen(request));
    strcpy(dup,request);
    char *tmp;
    tmp = strtok(dup," ");
    tweet_req->command = tmp;
    tmp = strtok(NULL," ");
    tweet_req->handler = atoi(tmp);
    tmp = strtok(NULL,"\r\n\r\n");
    tweet_req->datalength = atoi(tmp);
    tmp = strtok(NULL,"\0");
    tmp = tmp+3*sizeof(char);
    tweet_req->data = tmp;
    //printf("Command:%sHandler:%dDatalength:%ldData:%s\n",tweet_req->command, tweet_req->handler, tweet_req->datalength, tweet_req->data);


    /*LOGIN and SIGNUP request handling*/
    if (tweet_req->handler <= 0) {//if the user is asking for login request
        char *tmp1, *username, *password;
        tmp1 = strtok(tweet_req->data," ");
        username = tmp1;
        tmp1 = strtok(NULL,"\0");
        password = tmp1;
        printf("Received username: %s & password: %s\n",username,password);

        if (strcmp(tweet_req->command,"LOGIN") == 0) {
            printf("Login Requested. Authenticating '%s'...\n",username);
            pthread_mutex_lock(&args->th_mutex);
            result = login(args->conn,username,password);
            pthread_mutex_unlock(&args->th_mutex);
            //printf("%s %d %ld %s\n", result->command,result->st_code, result->dlength,result->data);
        }
        else if (strcmp(tweet_req->command,"SIGNUP") == 0) {
            printf("Signup Requested. Creating user account for '%s'...\n",username);
            pthread_mutex_lock(&args->th_mutex);
            result = signup(args->conn,username,password);
            pthread_mutex_unlock(&args->th_mutex);
            //printf("%s %d %ld %s\n", result->command,result->st_code, result->dlength,result->data);
        }
    }
    /*other Request Handling*/
    else {
        if (strcmp(tweet_req->command,"LOGOUT") == 0) {
            printf("LOGOUT Requested. Closing session...");
            pthread_mutex_lock(&args->th_mutex);
            result = logout(args->conn,tweet_req->handler);
            pthread_mutex_unlock(&args->th_mutex);
            //printf("%s %d %ld %s\n", result->command,result->st_code, result->dlength,result->data);
        }
        else {
            if (strcmp(tweet_req->command,"FOLLOW") == 0) {
                printf("FOLLOW requested");
                format = "INSERT INTO follow_tb VALUES((SELECT user_id FROM session WHERE ssid= %d),(SELECT user_id FROM users WHERE user_name='%s'))";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->handler,tweet_req->data);
                //result = process_query(args->conn, tweet_req->command, query);
            }
            else if (strcmp(tweet_req->command,"UNFOLLOW") == 0) {
                printf("UNFOLLOW requested");
                format = "DELETE FROM follow_tb WHERE follower= (SELECT user_id FROM session WHERE ssid=%d) AND following=(SELECT user_id FROM users WHERE user_name=('%s'))";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->handler,tweet_req->data);
                //result = process_query(args->conn, tweet_req->command, query);
            }

            else if (strcmp(tweet_req->command,"FOLLOWERS") == 0) {
                printf("FOLLOWERS requested");
                format = "SELECT user_name FROM users LEFT JOIN follow_tb ON users.user_id=follow_tb.follower WHERE follow_tb.following=(SELECT user_id FROM session WHERE ssid=(%d))";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->handler);
                //result = process_query(args->conn, tweet_req->command, query);
            }
            else if (strcmp(tweet_req->command,"FOLLOWING") == 0) {
                printf("FOLLOWING requested");
                format = "SELECT user_name FROM users LEFT JOIN follow_tb ON users.user_id=follow_tb.following WHERE follow_tb.follower=(SELECT user_id FROM session WHERE ssid=(%d))";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->handler);
                //result = process_query(args->conn, tweet_req->command, query);
            }
            else if (strcmp(tweet_req->command,"TWEET") == 0) {
                printf("TWEET requested");
                format = "INSERT INTO tweets(tweet_text,user_id) VALUES ('%s',(SELECT user_id FROM session WHERE ssid=%d))";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->data,tweet_req->handler);
                //result = process_query(args->conn, tweet_req->command, query);
            }
            else if (strcmp(tweet_req->command,"UNTWEET") == 0) {
                printf("UNTWEET requested");
                format = "DELETE FROM tweets WHERE tweet_id=%d AND user_id=(SELECT user_id FROM session WHERE ssid=%d)";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,atoi(tweet_req->data),tweet_req->handler);
                //result = process_query(args->conn, tweet_req->command, query);
            }
            else if (strcmp(tweet_req->command,"ALLTWEETS") == 0) {
                printf("ALLTWEETS requested");
                format = "SELECT tweet_text,tweet_id FROM tweets LEFT JOIN follow_tb ON tweets.user_id = follow_tb.following \
WHERE follow_tb.follower= (SELECT user_id FROM session WHERE ssid=%d) \
UNION SELECT tweet_text,tweet_id FROM tweets WHERE user_id=(SELECT user_id FROM session WHERE ssid=%d)";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->handler,tweet_req->handler);
                //result = process_query(args->conn, tweet_req->command, query);
            }
            else if (strcmp(tweet_req->command,"MYTWEETS") == 0) {
                printf("MYTWEETS requested");
                format = "SELECT tweet_text,tweet_id FROM tweets WHERE user_id IN (SELECT user_id FROM session WHERE ssid=%d) ORDER BY time_created DESC";
                query = (char *)malloc(strlen(format)+sizeof(tweet_req->handler)+strlen(tweet_req->data));
                bzero(query, sizeof(query));
                sprintf(query,format,tweet_req->handler);
                //result = process_query(args->conn, tweet_req->command, query);
            }

            pthread_mutex_lock(&args->th_mutex);
            printf("Query:%s\n",query);
            result = process_query(args->conn, tweet_req->command, query);
            pthread_mutex_unlock(&args->th_mutex);
            free(query);
        }
Example #9
0
void init_spl()
{
	memset(arena, 0, sizeof(arena));
	signup();
}
Example #10
0
void handle_client(conn_t *conn) {
    conn->user = NULL;
    for(; ;) {
        request_t *rqst = parse_args(conn->input);
        if(rqst != NULL) {
            if(IS_PROTOCOL(rqst, P_LOGIN)) {
                if(login(rqst->argv[1], rqst->argv[2]) == 0) {
                    conn->user = (t_user*) malloc(sizeof(t_user));
                    memcpy(conn->user, find_user_by_id(rqst->argv[1]), sizeof(t_user));
                    simple_response(0, conn);
                } else {
                    simple_response(1, conn);
                }
            } 
            else if(IS_PROTOCOL(rqst, P_SIGNUP)) {
                if(signup(rqst->argv[1], rqst->argv[2]) == 0 ) {
                    simple_response(0, conn);
                } else {
                    simple_response(1, conn);
                }
            } 
            else if(IS_PROTOCOL(rqst, P_EXIT)) {
                simple_response(0, conn);
                return;
            }
            else  if(conn->user != NULL) { //authorized user
                if(IS_PROTOCOL(rqst, P_BUY)) {
                    if(buy(conn->user->id, rqst->argv[1]) == 0)  {
                        simple_response(0, conn);
                    } else {
                        simple_response(1, conn);
                    }
                } else if(IS_PROTOCOL(rqst, P_QUERY)) {

                    t_ticket_list *list = query(rqst->argv[1], rqst->argv[2]);

                    write(conn->dfd, "*", 1);
                    char *tmp = ltoa(list->num);
                    int tmplen = strlen(tmp);
                    write(conn->dfd, tmp, tmplen);
                    write(conn->dfd, CRLF, CLLEN);

                    free(tmp);

                    tmp = ltoa(sizeof(t_ticket));
                    tmplen = strlen(tmp);
                    int i;
                    for (i = 0; i < list->num; ++i) {
                        write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN);
                        write(conn->dfd, &list->data[i], sizeof(t_ticket));
                    }
                    free(tmp);
                } else if(IS_PROTOCOL(rqst, P_USER_INFO)) {

                    char *tmp = ltoa(sizeof(t_user));
                    int tmplen = strlen(tmp);
                    write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN);
                    write(conn->dfd, conn->user, sizeof(t_user));

                } else if(IS_PROTOCOL(rqst, P_USER_UPD)) {
                    if(update_user_info(conn->user->id, rqst->argv[1], rqst->argv[2], rqst->argv[3]) == 0)  {
                        memcpy(conn->user, find_user_by_id(conn->user->id), sizeof(t_user));
                        simple_response(0, conn);
                    } else {
                        simple_response(1, conn);
                    }

                } else if(IS_PROTOCOL(rqst, P_QUERY_BUY)) {
                    t_ticket_list *list = query_buy(conn->user->id);

                    write(conn->dfd, "*", 1);
                    char *tmp = ltoa(list->num);
                    int tmplen = strlen(tmp);
                    write(conn->dfd, tmp, tmplen);
                    write(conn->dfd, CRLF, CLLEN);

                    free(tmp);

                    tmp = ltoa(sizeof(t_ticket));
                    tmplen = strlen(tmp);
                    int i;
                    for (i = 0; i < list->num; ++i) {
                        write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN);
                        write(conn->dfd, &list->data[i], sizeof(t_ticket));
                    }
                    free(tmp);

                } else if(IS_PROTOCOL(rqst, P_REFUND)) {
                    if(refund(conn->user->id, rqst->argv[1]) == 0)  {
                        simple_response(0, conn);
                    } else {
                        simple_response(1, conn);
                    }
                }
                else if(IS_PROTOCOL(rqst, P_TICKET) && conn->user->type == 1) {
                    t_ticket *tkt = load_ticket(rqst->argv[1]);
                    if(tkt == NULL) {
                        simple_response(1, conn);
                    } else {
                        char *tmp = ltoa(sizeof(t_ticket));
                        write(conn->dfd, "?", 1); write(conn->dfd, tmp, strlen(tmp));write(conn->dfd, CRLF, CLLEN);
                        write(conn->dfd, tkt, sizeof(t_ticket));
                        free(tmp);
                    }
                } else if(IS_PROTOCOL(rqst, P_TKT_UPDATE) && conn->user->type == 1) {
                    if(add_update_ticket(rqst->argv[1],
                            rqst->argv[2],
                            rqst->argv[3],
                            rqst->argv[4],
                            rqst->argv[5],
                            rqst->argv[6],
                            rqst->argv[7],
                            rqst->argv[8],
                            rqst->argv[9]
                            ) == 0) {
                        simple_response(0, conn);
                    } else {
                        simple_response(1, conn);
                    }
                } else if(IS_PROTOCOL(rqst, P_STN_ADD) && conn->user->type == 1) {
                    if(add_station(rqst->argv[1]) == 0)  {
                        simple_response(0, conn);
                    } else {
                        simple_response(1, conn);
                    }

                } else if(IS_PROTOCOL(rqst, P_STN_DEL) && conn->user->type == 1) {
                    if(del_station(rqst->argv[1]) == 0)  {
                        simple_response(0, conn);
                    } else {
                        simple_response(1, conn);
                    }

                } else if(IS_PROTOCOL(rqst, P_STN_ALL) && conn->user->type == 1) {
                    t_station_list *list = all_station();

                    write(conn->dfd, "*", 1);
                    char *tmp = ltoa(list->num);
                    int tmplen = strlen(tmp);
                    write(conn->dfd, tmp, tmplen);
                    write(conn->dfd, CRLF, CLLEN);

                    free(tmp);

                    tmp = ltoa(sizeof(t_station));
                    tmplen = strlen(tmp);
                    int i;
                    for (i = 0; i < list->num; ++i) {
                        write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN);
                        write(conn->dfd, &list->data[i], sizeof(t_station));
                    }
                    free(tmp);

                }
            } 
            else {
                simple_response(1, conn);
            }
        }
    }
}
Example #11
0
int crypto(){

	char username[BUFSIZ], *password="";  
  char buf[BUFSIZ];                 
  char *user_file, *pass_file;       
  char filename[]="psss";            
  FILE *infile;                     
	int flag=0;
	int emptyflag=0;
	char *crybuf;
  
  printf("Username: "******"%s", username);
 
  password = getpass("Password: "******"r")) == NULL){

    printf("\nFile error!\nAborting...\n");
	
  } else {

  
  while (!feof(infile)) {

    
      buf[0] = '\0';
   
      fscanf(infile, "%s", buf);

      if(strlen(buf) == 0) continue;

      user_file = buf;

      pass_file = strchr(buf, ':');

      pass_file[0] = '\0';

      pass_file++;

      if(strcmp(user_file, username) == 0){

       	crybuf=crypt(password, pass_file);
 
 	if(strcmp(crybuf, pass_file) == 0){
       
	flag=1;

        } else {
	if(flag==0)
	
          printf("Invalid password!\n\n");
		
        }  
	        
        break;

      }  
		 
  	emptyflag=1;
	flag=999;
    }

  } 
if(strlen(buf)==0 && emptyflag==0){
printf("We could not find your Login credentials.Please Register :\n");
	flag=signup();
}
	
  
 fclose(infile);
return flag;
} 
Example #12
0
int main(int argc, char * argv[])
{
	int sockfd;
	char buf[256];
	char nbuf[256];

	struct sockaddr_in serveraddr;
	serveraddr.sin_family = AF_INET;
	serveraddr.sin_port = htons(8888);
	serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
	
	socklen_t serverlen = sizeof(serveraddr);
	int recvsize = 0;
	char *p = NULL;
	usrname[0] = '\0';

	do
	{
		if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
		{
			perror("socket");
			exit(EXIT_FAILURE);
		}
		if(connect(sockfd,(struct sockaddr *)&serveraddr
			, serverlen) < 0)
		{
			perror("connect");
			exit(EXIT_FAILURE);
		}
		p = fgets(buf, sizeof(buf), stdin);

		if(strncmp(buf,"search",6) == 0)
		{
			search(sockfd, buf);
		}else if(strncmp(buf,"history",7) == 0)
		{
			history(sockfd, buf);
		}else if(strncmp(buf,"login",5) == 0)
		{
			login(sockfd, buf);
		}else if(strncmp(buf,"signup",6) == 0)
		{
			signup(sockfd, buf);
		}else if(strncmp(buf,"logout",6) == 0)
		{
			logout(sockfd, buf);
		}else if(strncmp(buf,"help",4) == 0)
		{
			help();
		}else if(strncmp(buf,"quit",4) == 0)
		{
			logout(sockfd, buf);
		}else
		{
			printf("illegal command, please read the "
					"help for the right "
					"command\n");
		}

		close(sockfd);
	
	}while(strcmp(buf, "quit\n"));
	return 0;
}
Example #13
0
void *Server::recvDataSocket(void *client_sock) {
    cout << "Thread listener created" << endl;
    
    int active = j;
    cout << "recv on :" <<  active << endl;
    int c_sock = *((int*)client_sock);
    int cl_sock = *((int*)c_sock);
    char* buff; buff = new char[MAXBUF];
    bzero(buff,MAXBUF); int len; char *str;
    
    cout << "Client Socket: " << users[active].getID() << endl;
    cout << "status client "<< users[active].getID() << ": "<< users[active].getStatus() << endl;

    /* Main loop */
    while(users[active].getStatus()=="online"){
        
        cout << "lock listener called" << endl;
        users[active].setMessage("");
        bzero(buff,MAXBUF);
        len = recv(users[active].getID(), buff , MAXBUF , 0); //receive message from user
        printf("%s\n",buff);
        buff = strtok(buff,"\n\r");
        users[active].setMessage((string)buff);
        
        if (len>=0){
            string dest = getDestination(users[active].getMessage());
            int id_dest = searchIDbyName(dest);
            
            if(users[active].getMessage()=="logout"){   //if user type "logout"
                cout << "masuk" << endl;
                closeClientSocket(users[active].getID());
                users[active].setStatus("offline");
                cout << "client "<< users[active].getID() << ": "<< users[active].getStatus() << endl;
                break;
            } else if(dest=="--login--"){
                int success = 0;
                listUser();
                string usr=getUsernameFromMessage(users[active].getMessage());
                string pass=getPasswordFromMessage(users[active].getMessage());
                cout << "usr: "******"usr length: " << usr.length() << endl;
                cout << "pass: "******"pass length: " << pass.length() << endl;
                success = login(usr,pass);
                cout << "success: " << success << endl;
                if (success>0){
                    // char * convert; convert = new char[32];
                    string msg = "Welcome to the MESSENGER";
                    write(users[active].getID(),msg.c_str(),strlen(msg.c_str()));
                    users[active].setName(usr);
                }else{
                    users[active].setStatus("offline");
                    logger.loggedIn(usr);
                   	closeClientSocket(users[active].getID());
                }
            } else if (dest=="--register--"){
                string usr=getUsernameFromMessage(users[active].getMessage());
                string pass=getPasswordFromMessage(users[active].getMessage());
                int success = 0;
                success = signup(usr,pass);
                cout <<"success: " << success << endl;
                if (success>0){
                    string msg = "account succesfully created";
                    write(users[active].getID(),msg.c_str(),strlen(msg.c_str()));
                    users[active].setName(usr);
                    logger.terdaftar(usr);
                }
            }else if(dest=="--create--"){
                string grpname = getMessage(users[active].getMessage());
                cout << grpname << endl;
                cout << grpname.length() << endl;
                //Server::group.newGroup(grpname);
                group.newGroup(strdup(grpname.c_str()));
                write(users[active].getID(),"Group succesfully created",25);
            } else if(dest=="--join--"){
                string group=getUsernameFromMessage(users[active].getMessage());
                string name=getPasswordFromMessage(users[active].getMessage());
                cout << group;
                cout << name;
                /*
                char* membername;
                strcpy(membername, name.c_str());
                cout << groupname;
                cout << membername;
                */
                Server::group.addNewMemberGroup(group,name);
                
            }else if(dest=="--leave--"){
                string group=getUsernameFromMessage(users[active].getMessage());
                string name=getPasswordFromMessage(users[active].getMessage());
                char* groupname;
                strcpy(groupname, group.c_str());
                char* membername;
                strcpy(membername, name.c_str());
                Server::group.delMember(groupname,membername);
                logger.left(membername, groupname);
            } else if(dest=="--group--"){
            	string group=getUsernameFromMessage(users[active].getMessage());
                string message=getPasswordFromMessage(users[active].getMessage());
                char* groupname;
                strcpy(groupname, group.c_str());
                cout << "group message: " << message << endl;
                sendToAll(groupname,message);
            }else{
                 cout << "dest: " << dest << endl;
                 cout << "len dest: " << dest.length() << endl;
                 cout << "id_dest" << id_dest << endl;
                 cout << "Message: " << getMessage(users[active].getMessage()) << endl;
                 cout << "Message len: " << getMessage(users[active].getMessage()).length() << endl;
                 cout << "test : " << active << endl;
                 // users[active].setLength(len);
                 if(id_dest!=-1){
                 	string concatmsg = users[active].getName() + " : " + getMessage(users[active].getMessage());
                 	users[id_dest].setMessage(concatmsg);
	                cout << "test lawan: " << users[id_dest].getMessage()<< endl;
	                cout << "status: " << users[active].getStatus() << endl;
	             	users[id_dest].setLength(len);
                 }
            }
        }
        cout << "bufer[" << active << "] : " << users[active].getMessage().length() << endl;
//        cout << "unlock listener called" << endl;
    }
    
    cout << "Thread-listener for sock: " << active << " die..........." << endl;
    pthread_exit(NULL);
}
Example #14
0
Client::Client(QObject *parent, const QString &filename)
    :QObject(parent), refusable(true), status(NotActive), alive_count(1),
    nullification_dialog(NULL)
{
    ClientInstance = this;    

    callbacks["checkVersion"] = &Client::checkVersion;
    callbacks["setup"] = &Client::setup;
    callbacks["addPlayer"] = &Client::addPlayer;
    callbacks["removePlayer"] = &Client::removePlayer;
    callbacks["startInXs"] = &Client::startInXs;
    callbacks["arrangeSeats"] = &Client::arrangeSeats;
    callbacks["startGame"] = &Client::startGame;
    callbacks["hpChange"] = &Client::hpChange;    
    callbacks["playSkillEffect"] = &Client::playSkillEffect;    
    callbacks["closeNullification"] = &Client::closeNullification;    
    callbacks["playCardEffect"] = &Client::playCardEffect;
    callbacks["clearPile"] = &Client::clearPile;
    callbacks["setPileNumber"] = &Client::setPileNumber;    
    callbacks["gameOver"] = &Client::gameOver;
    callbacks["killPlayer"] = &Client::killPlayer;
    callbacks["gameOverWarn"] = &Client::gameOverWarn;
    callbacks["showCard"] = &Client::showCard;
    callbacks["setMark"] = &Client::setMark;
    callbacks["log"] = &Client::log;
    callbacks["speak"] = &Client::speak;
    callbacks["increaseSlashCount"] = &Client::increaseSlashCount;
    callbacks["attachSkill"] = &Client::attachSkill;
    callbacks["detachSkill"] = &Client::detachSkill;
    callbacks["moveFocus"] = &Client::moveFocus;
    callbacks["setEmotion"] = &Client::setEmotion;
    callbacks["skillInvoked"] = &Client::skillInvoked;
    callbacks["acquireSkill"] = &Client::acquireSkill;

    callbacks["moveNCards"] = &Client::moveNCards;
    callbacks["moveCard"] = &Client::moveCard;
    callbacks["drawCards"] = &Client::drawCards;
    callbacks["drawNCards"] = &Client::drawNCards;

    // interactive methods
    callbacks["activate"] = &Client::activate;
    callbacks["doChooseGeneral"] = &Client::doChooseGeneral;
    callbacks["doGuanxing"] = &Client::doGuanxing;
    callbacks["doGongxin"] = &Client::doGongxin;
    callbacks["askForDiscard"] = &Client::askForDiscard;
    callbacks["askForSuit"] = &Client::askForSuit;
    callbacks["askForKingdom"] = &Client::askForKingdom;
    callbacks["askForSinglePeach"] = &Client::askForSinglePeach;
    callbacks["askForCardChosen"] = &Client::askForCardChosen;
    callbacks["askForCard"] = &Client::askForCard;
    callbacks["askForUseCard"] = &Client::askForUseCard;
    callbacks["askForSkillInvoke"] = &Client::askForSkillInvoke;
    callbacks["askForChoice"] = &Client::askForChoice;
    callbacks["askForNullification"] = &Client::askForNullification;
    callbacks["askForCardShow"] = &Client::askForCardShow;
    callbacks["askForPindian"] = &Client::askForPindian;
    callbacks["askForYiji"] = &Client::askForYiji;
    callbacks["askForPlayerChosen"] = &Client::askForPlayerChosen;

    callbacks["fillAG"] = &Client::fillAG;
    callbacks["askForAG"] = &Client::askForAG;
    callbacks["takeAG"] = &Client::takeAG;
    callbacks["clearAG"] = &Client::clearAG;

    ask_dialog = NULL;
    use_card = false;

    Self = new ClientPlayer(this);
    Self->setScreenName(Config.UserName);
    Self->setProperty("avatar", Config.UserAvatar);
    connect(Self, SIGNAL(turn_started()), this, SLOT(clearTurnTag()));
    connect(Self, SIGNAL(role_changed(QString)), this, SLOT(notifyRoleChange(QString)));

    if(!filename.isEmpty()){
        socket = NULL;
        recorder = NULL;

        replayer = new Replayer(this, filename);
        connect(replayer, SIGNAL(command_parsed(QString)), this, SLOT(processCommand(QString)));
    }else{
        socket = new NativeClientSocket;

        socket->setParent(this);
        connect(socket, SIGNAL(message_got(char*)), this, SLOT(processReply(char*)));
        connect(socket, SIGNAL(error_message(QString)), this, SIGNAL(error_message(QString)));
        connect(socket, SIGNAL(connected()), this, SLOT(signup()));
        socket->connectToHost();

        recorder = new Recorder(this);
        connect(socket, SIGNAL(message_got(char*)), recorder, SLOT(record(char*)));

        replayer = NULL;
    }
}
Example #15
0
int main()
{
	int condition;
	printf("Enter 'help' to view available options: ");
	
	int ch=0,reply,status,checkout_flag=0;
	char command[COMMAND_LENGTH],buf[BUF_LENGTH],choice[1];

	while(1)
	{
		printf("\n>");
		scanf("%s",command);
		ch=choiceValue(command);
		switch(ch)
		{
			case 1:
					help();
					break;

			case 2:
					if(login_session==1)
						printf("Already logged in..!!");
					else
						signup();
					break;

			case 3:
					if(login_session==1)
						printf("Already logged in..!!");
					else
						login_session = login();
					break;

			case 4:
					if(login_session==0)
						printf("Not yet logged in..!!");
					else
					{
						if(checkout_flag==0)
						{
							printf("\nYour cart file will be deleted..Do you want to logout(y/n)??");
							scanf("%s",choice);
							if((choice[0]=='y')||(choice[0]=='Y'))
							{
								status = remove(CART_FILE);
								
								login_session=0;
								strcpy(buf,"logout");
								reply = sendtoserver(buf);
 
 								if( status == 0 )
 									printf("Cart file deleted.\n");
 								else
 								{
 									printf("Cart file is already deleted.\n");
 								}
 							}
 							else 
								continue;
						}
						else
						{
							login_session=0;
							strcpy(buf,"logout");
							reply = sendtoserver(buf);

						}
						
					}
					break;

			case 5:
					if(login_session==0)
						printf("Please login to view catalog..!!");
					else
						viewcatalog();
					break;

			case 6:
					if(login_session==0)
						printf("Please login to search an item..!!");
					else
						search();
					break;

			case 7:
					if(login_session==0)
						printf("Please login to add an item..!!");
					else
						addtocart();
					break;

			case 8:
					if(login_session==0)
						printf("Please login to view your cart..!!");
					else
						viewcart();
					break;

			case 9:
					if(login_session==0)
						printf("Please login to remove an item from your cart..!!");
					else
						removefromcart();
					break;

			case 10:
					if(login_session==0)
						printf("Please login to checkout your cart..!!");
					else
					{
						checkout();
						checkout_flag = 1;
					}
					break;

			case 11:
					return 0;

			default:
					printf("Invalid Command\n");
		}
	}
}
Example #16
0
Client::Client(QObject *parent, const QString &filename)
    :QObject(parent), refusable(true), status(NotActive), alive_count(1),
    slash_count(0)
{
    ClientInstance = this;    

    callbacks["checkVersion"] = &Client::checkVersion;
    callbacks["setup"] = &Client::setup;
    callbacks["addPlayer"] = &Client::addPlayer;
    callbacks["removePlayer"] = &Client::removePlayer;
    callbacks["startInXs"] = &Client::startInXs;
    callbacks["arrangeSeats"] = &Client::arrangeSeats;
    callbacks["startGame"] = &Client::startGame;
    callbacks["hpChange"] = &Client::hpChange;
    callbacks["clearPile"] = &Client::clearPile;
    callbacks["setPileNumber"] = &Client::setPileNumber;    
    callbacks["gameOver"] = &Client::gameOver;
    callbacks["killPlayer"] = &Client::killPlayer;
    callbacks["revivePlayer"] = &Client::revivePlayer;
    callbacks["warn"] = &Client::warn;
    callbacks["showCard"] = &Client::showCard;
    callbacks["setMark"] = &Client::setMark;
    callbacks["log"] = &Client::log;
    callbacks["speak"] = &Client::speak;
    callbacks["increaseSlashCount"] = &Client::increaseSlashCount;
    callbacks["attachSkill"] = &Client::attachSkill;
    callbacks["detachSkill"] = &Client::detachSkill;
    callbacks["moveFocus"] = &Client::moveFocus;
    callbacks["setEmotion"] = &Client::setEmotion;
    callbacks["skillInvoked"] = &Client::skillInvoked;
    callbacks["acquireSkill"] = &Client::acquireSkill;
    callbacks["addProhibitSkill"] = &Client::addProhibitSkill;
    callbacks["animate"] = &Client::animate;
    callbacks["setPrompt"] = &Client::setPrompt;
    callbacks["jilei"] = &Client::jilei;
    callbacks["judgeResult"] = &Client::judgeResult;
    callbacks["setScreenName"] = &Client::setScreenName;
    callbacks["setFixedDistance"] = &Client::setFixedDistance;
    callbacks["pile"] = &Client::pile;
    callbacks["transfigure"] = &Client::transfigure;

    callbacks["playSkillEffect"] = &Client::playSkillEffect;
    callbacks["playCardEffect"] = &Client::playCardEffect;
    callbacks["playAudio"] = &Client::playAudio;

    callbacks["moveNCards"] = &Client::moveNCards;
    callbacks["moveCard"] = &Client::moveCard;
    callbacks["drawCards"] = &Client::drawCards;
    callbacks["drawNCards"] = &Client::drawNCards;   

    // interactive methods
    callbacks["activate"] = &Client::activate;
    callbacks["doChooseGeneral"] = &Client::doChooseGeneral;
    callbacks["doChooseGeneral2"] = &Client::doChooseGeneral2;
    callbacks["doGuanxing"] = &Client::doGuanxing;
    callbacks["doGongxin"] = &Client::doGongxin;
    callbacks["askForDiscard"] = &Client::askForDiscard;
    callbacks["askForExchange"] = &Client::askForExchange;
    callbacks["askForSuit"] = &Client::askForSuit;
    callbacks["askForKingdom"] = &Client::askForKingdom;
    callbacks["askForSinglePeach"] = &Client::askForSinglePeach;
    callbacks["askForCardChosen"] = &Client::askForCardChosen;
    callbacks["askForCard"] = &Client::askForCard;
    callbacks["askForUseCard"] = &Client::askForUseCard;
    callbacks["askForSkillInvoke"] = &Client::askForSkillInvoke;
    callbacks["askForChoice"] = &Client::askForChoice;
    callbacks["askForNullification"] = &Client::askForNullification;
    callbacks["askForCardShow"] = &Client::askForCardShow;
    callbacks["askForPindian"] = &Client::askForPindian;
    callbacks["askForYiji"] = &Client::askForYiji;
    callbacks["askForPlayerChosen"] = &Client::askForPlayerChosen;
    callbacks["askForGeneral"] = &Client::askForGeneral;

    callbacks["fillAG"] = &Client::fillAG;
    callbacks["askForAG"] = &Client::askForAG;
    callbacks["takeAG"] = &Client::takeAG;
    callbacks["clearAG"] = &Client::clearAG;

    // 3v3 mode & 1v1 mode
    callbacks["fillGenerals"] = &Client::fillGenerals;
    callbacks["askForGeneral3v3"] = &Client::askForGeneral3v3;
    callbacks["askForGeneral1v1"] = &Client::askForGeneral3v3;
    callbacks["takeGeneral"] = &Client::takeGeneral;
    callbacks["startArrange"] = &Client::startArrange;
    callbacks["askForOrder"] = &Client::askForOrder;
    callbacks["askForDirection"] = &Client::askForDirection;
    callbacks["recoverGeneral"] = &Client::recoverGeneral;
    callbacks["revealGeneral"] = &Client::revealGeneral;

    ask_dialog = NULL;
    use_card = false;

    Self = new ClientPlayer(this);
    Self->setScreenName(Config.UserName);
    Self->setProperty("avatar", Config.UserAvatar);
    connect(Self, SIGNAL(phase_changed()), this, SLOT(clearTurnTag()));
    connect(Self, SIGNAL(role_changed(QString)), this, SLOT(notifyRoleChange(QString)));

    if(!filename.isEmpty()){
        socket = NULL;
        recorder = NULL;

        replayer = new Replayer(this, filename);
        connect(replayer, SIGNAL(command_parsed(QString)), this, SLOT(processCommand(QString)));
    }else{
        socket = new NativeClientSocket;
        socket->setParent(this);

        recorder = new Recorder(this);

        connect(socket, SIGNAL(message_got(char*)), recorder, SLOT(record(char*)));
        connect(socket, SIGNAL(message_got(char*)), this, SLOT(processReply(char*)));
        connect(socket, SIGNAL(error_message(QString)), this, SIGNAL(error_message(QString)));
        connect(socket, SIGNAL(connected()), this, SLOT(signup()));
        socket->connectToHost();

        replayer = NULL;
    }

    lines_doc = new QTextDocument(this);

    prompt_doc = new QTextDocument(this);
    prompt_doc->setTextWidth(350);
    prompt_doc->setDefaultFont(QFont("SimHei"));
}
Example #17
0
string solve(string command,user*& cur_user)
{
  vector <string> commands;
  string x;

  string sol;
  commands=parse(command);
  x=commands[0];
  if(x=="exit" || x=="disconnect")
    return x;
  if(x=="signup")
    sol=signup(cur_user,commands);
  if(x=="signin")
    sol=signin(cur_user,commands);
  if(x=="signout" && commands.size()==1)
    {
      cur_user=NULL;
      return "signing out completed.\n";
    }
  if(x=="show_boards")
    sol=show_boards(cur_user);
  if(x=="enter_board")
    sol=enter_board(cur_user,commands);
  if(x=="add_user")
    sol=add_user(cur_user,commands);
  if(x=="remove_user_from_board")
    sol=remove_user_from_board(cur_user,commands);
  if(x=="show_lists" && commands.size()==1)
    sol=show_lists(cur_user);
  if(x=="show_cards")
    sol=show_cards(cur_user,commands);
  if(x=="show_card")
    sol=show_card(cur_user,commands);
  if(x=="create_board")
    sol=create_board(cur_user,commands);
  if(x=="remove_board")
    sol=remove_board(cur_user,commands);
  if(x=="add_list")
    sol=add_list(cur_user,commands);
  if(x=="remove_list")
    sol=remove_list(cur_user,commands);
  if(x=="add_card")
    sol=add_card(cur_user,commands);
  if(x=="remove_card")
    sol=remove_card(cur_user,commands);
  if(x=="move_card")
    sol=move_card(cur_user,commands);
  if(x=="rename_card")
    sol=rename_card(cur_user,commands);
  if(x=="edit_card_description")
    sol=edit_card_des(cur_user,commands);
  if(x=="edit_card_due_date")
    sol=edit_card_date(cur_user,commands);
  if(x=="assign_user")
    sol=assign(cur_user,commands);
  if(x=="remove_user")
    sol=remove_user_from_card(cur_user,commands);
  if(x=="comment")
    sol=commenting(cur_user,commands);
  if(x=="filter")
    sol=filter(cur_user,commands);
  if(sol.size()==0)
    sol="Invalid command.\n";
  return sol;
     
}
Example #18
0
setupConnection()
{
	int n,sockfd,newsockfd,clilen,cli,i=0, choice;
	char copystring[50];

	/* creating the socket */
	cli_addr.sin_family=PF_INET;
	cli_addr.sin_port=htons(4013);
	cli_addr.sin_addr.s_addr=htons(INADDR_ANY);
	sockfd=socket(PF_INET,SOCK_DGRAM,0);

	i=bind(sockfd,(struct sockaddr*) &cli_addr,sizeof(cli_addr)); /* binding the socket */
	printf("\n\nserver started\n");
	printf("waiting for client\n");

	memset(buf, 0, sizeof(buf));
	cli=sizeof(cli_addr);
	n=recvfrom(sockfd,buf,sizeof(buf),0,(struct sockaddr *) &cli_addr, &cli); /* recieving data from the client */

	memset(copystring, 0, sizeof(copystring));
	strcpy(copystring,buf);
	pch = strtok(copystring," "); /* chop the request header from the wired string */

	/* assigning integer values for each possible request header */
	if ( strcasecmp(pch,"register") == 0)
		choice = 1;
	else if ( strcasecmp(pch,"login") == 0)
		choice = 2;
	else if ( strcasecmp(pch,"find") == 0)
		choice = 3;
	else if ( strcasecmp(pch,"chat") == 0)
		choice = 4;

	/* switching to corresponding functions based on request header */
	switch(choice)
	{
		case 1:
			signup();
			break;
		
		case 2:
			login();
			break;
		
		case 3:
printf("\ncheck0");
			list();
			break;
		
		case 4:
			chat();
			/* sending the message over the network */
			n=sendto(sockfd,buf,sizeof(buf),0,(struct sockaddr*) &clients[tocno].cli_addr,sizeof(clients[tocno].cli_addr));
			break;
		
		default:
			printf("\nswitch error\n");
	}
        
	n=sendto(sockfd,str,sizeof(str),0,(struct sockaddr*) &cli_addr,sizeof(cli_addr)); /* replying to the client */


    close(sockfd);      	
}