Example #1
0
int RoomMng::AddUser(int id, int roomid, css_stream_t* stream)
{
	UserClient* user = FindUser(id);
	if (user){ // same user login and pre-user still in room
		RemoveUser(id);
	}
	user = new UserClient(id, roomid, stream);
	if (!user){
		return -1;
	}
	UserRoom* ur = FindRoom(roomid);
	if (ur){
		ur->AddClient(user);
		stream->data = ur;
	}
	else {
		ur = new UserRoom(roomid);
		if (!ur){
			delete user;
			return -1;
		}
		else{
			room_map_.insert({ roomid, ur });
			ur->AddClient(user);
			stream->data = ur;
		}
	}
	ur->SendBackOtherOnlineUser(user);
	return 0;
}
Example #2
0
void BigMamaRoomManager::ReportRoundMark(unsigned int nRoomID, unsigned int nRoleID, const std::string &rMD5Code,
    unsigned int nMark, char nKeyRank, unsigned char nRound, const std::vector<char> &rRoundRank )
{
    if ( RoomRoundRank_None < nKeyRank && nKeyRank < RoomRoundRank_Max && nRound > 0 )
    {
        DanceBaseRoom *pRoom = FindRoom( nRoomID );

        if ( pRoom == NULL || !pRoom->HasStart() )
        {
            return;
        }

        std::string strCode;
        std::vector<int> vectRoundRank( rRoundRank.begin(), rRoundRank.end() );
        Formatter(strCode) << pRoom->GetCheckCode() << (int)nRound << (int)nKeyRank << nMark;

        for ( unsigned int i = 0; i < vectRoundRank.size(); ++i )
        {
            std::string strRank;
            Formatter(strRank) << vectRoundRank[i];
            strCode.append( strRank );
        }

        unsigned char szMD5Code[16] = {0};
        MDString( strCode.c_str(), szMD5Code );
        BinaryData2String( szMD5Code, sizeof(szMD5Code) ).swap( strCode );

        if ( rMD5Code != strCode )
        {
            return;
        }

        pRoom->RecvRoundMark( nRoleID, (int)pRoom->GetPlayMusicMode(), nRound, nMark, nKeyRank, vectRoundRank );
    }
}
Example #3
0
void BigMamaRoomManager::Start(unsigned int nRoomID)
{
    DanceBaseRoom *pRoom = FindRoom( nRoomID );

    if ( pRoom == NULL )
        return;

    pRoom->Start();

    GameMsg_S2C_StartRoomSuc startMsg;
    pRoom->SendMessage( startMsg );
}
Example #4
0
int RoomMng::RemoveUser(int id)
{
	UserClient* user = FindUser(id);
	if (!user){
		return 0;
	}
	UserRoom* ur = FindRoom(user->roomid());
	if (!ur){// finded user, so couldn't finded user room
		delete user;
		return -1;
	}
	ur->RemoveClient(user);
	delete user;
	// TODO: remove room when user is empty;
	return 0;
}
Example #5
0
bool BigMamaRoomManager::Prepare(unsigned int nRoomID, unsigned char nPhoneOS, std::string &rCheckKey, std::string &rStage)
{
    DanceBaseRoom *pRoom = FindRoom( nRoomID );

    if ( pRoom == NULL )
        return false;

    pRoom->Prepare();

    if ( !LoadStageInfo( pRoom, nPhoneOS, rStage ) )
    {
        RemoveRoom( nRoomID );

        return false;
    }

    rCheckKey = pRoom->GetCheckCode();

    return true;
}
Example #6
0
// 把进度广播给房间里的所有人
void BigMamaRoomManager::OnLoadingProgress(unsigned int nRoleID, unsigned int nRoomID, unsigned char nRate)
{ // 房间里只有一个人, 把进度转发给他自己,
    DanceBaseRoom *pRoom = FindRoom(nRoomID);

    if (pRoom == NULL)
        return;
    else if (pRoom->GetState() != EDanceRoomState_Preparing) // 只有在这
        return;
    
    CRoleEntity *pRole = CPlayerManager::Instance().GetEntityByRoleID(nRoleID);
    if (NULL == pRole)
        return;

    GameMsg_S2C_LoadingStartRoomProgress msgLoadingSend;
    msgLoadingSend.m_nRoleID = nRoleID;
    msgLoadingSend.m_nRate = nRate >= 100 ? 100 : nRate;
    pRole->SendPlayerMsg(&msgLoadingSend);

    return ;
}
Example #7
0
bool BigMamaRoomManager::End(unsigned int nRoomID, unsigned int nRoleID, unsigned int &rScore, CRoomMarkInfo &rMark)
{
    DanceBaseRoom *pRoom = FindRoom( nRoomID );

    if ( pRoom == NULL )
        return false;
    else if ( pRoom->GetDancerPos( nRoleID ) == INVALID_DANCE_ROOM_POS )
        return false;
    else if ( !pRoom->HasStart() )
        return false;

    if ( pRoom->HasLegalEndTime() )
    {
        pRoom->CalcDanceResult();
        rScore = pRoom->GetDancerScore( nRoleID );
        pRoom->GetDancerMark( nRoleID, rMark );
    }

    pRoom->End();

    RemoveRoom( nRoomID );

    return true;
}
Example #8
0
void flat(void)
{
char iroom[80],iphone[80],add_quit;
char option,sortopt,exit_opt;
int phone_check,room_check,delete_check,sort_check,list_check;
int iroom_search,iroom_del;
int int_iroom,total_entries;
int error_iphone,error_iroom;
long int longint_iphone;
long int iphone_search;
long int iphone_del;


strcpy(dbload, "DATABASE ERROR...");

do
 {
  do
   { option = menu_flat();
     if (option == '1')
     {  current_e_add=0;
	for (i=total_entry; i < MAXDB; i++)
	{   clrscr();
	    remakescreen();
	    screen_draw_flat();
	    gotoxy(1,4);
	    printf("## ADD NEW ENTRY ##");
	    gotoxy(1,25);
	    cprintf("Please Add Your Entry, leave blank to reach to Main Menu..");
	    gotoxy(1,6);
	    printf("Enter Room  Number[%3d]: ",i+1);
	    gets(iroom);

	    if (iroom[0] == '\0' )
	    {  gotoxy(1,25);
	       cprintf("You chose to quit: Entry %d was not added to the database.",i+1);
	       getch();
	       break;
	    }
	    printf("Enter Phone Number[%3d]: ",i+1);
	    gets(iphone);

	    if (iphone[0] == '\0')
	    {  gotoxy(1,25);
	       cprintf("You chose to quit: Entry %d was not added to the database.",i+1);
	       getch();
	       break;
	    }

	    error_iroom = chkdig(iroom,4);
	    error_iphone = chkdig(iphone,8);

	    while(error_iroom != 0)
	    {	if (error_iroom == -1)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("## ADD NEW ENTRY ##");
		   gotoxy(1,25);
		   cprintf("Error: Room  Number - out of Range, Your entry was greater than 4 digits. ");
		   gotoxy(1,6);
		   printf("Renter Room  Number[%3d]: ",i+1);
		   gets(iroom);
		}
		if (error_iroom == -2)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("*** Add Entry ***");
		   gotoxy(1,25);
		   cprintf("Error: Room  Number - Character(s) detected, character(s) are not allowed.");
		   gotoxy(1,6);
		   printf("Renter Room  Number[%3d]: ",i+1);
		   gets(iroom);
		}
		error_iroom = chkdig(iroom,4);
	    }
	    while(error_iphone !=0)
		{	if (error_iphone == -1)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("## ADD NEW ENTRY ##");
		   gotoxy(1,25);
		   cprintf("Error: Phone Number - out of Range, Your entry was greater than 8 digits. ");
		   gotoxy(1,6);
		   printf("Room  Number[%3d] Entry: %s",i+1,iroom);
		   gotoxy(1,7);
		   printf("Renter Phone Number[%3d]: ",i+1);
		   gets(iphone);
		}
		if (error_iphone == -2)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("## ADD NEW ENTRY ##");
		   gotoxy(1,25);
		   cprintf("Error: Phone Number - Character(s) detected, character(s) are not allowed.");
		   gotoxy(1,6);
		   printf("Room  Number[%3d] Entry: %s",i+1,iroom);
		   gotoxy(1,7);
		   printf("Renter Phone Number[%3d]: ",i+1);
		   gets(iphone);
		}
		error_iphone = chkdig(iphone,8);
	    }
	    if (error_iroom == 0 && error_iphone == 0)
	    {  int_iroom = atoi(iroom);
	       longint_iphone = atol(iphone);

	       current_e_add++;
	       add_entry(int_iroom,longint_iphone);
	    }
	}
	if (total_entry == MAXDB)
	{  gotoxy(1,25);
	   cprintf("\aDatabase is full!: %d entries were added, ",total_entry);
	   cprintf("that is the Maximum No. I can hold.");
	   getch();
	}
     }
     else
     if (option == '2')
     {  del_entry = 0; 	clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Delete Entry ##");
	gotoxy(1,6);
	printf("Enter room  number to delete: ");
	scanf("%d",&iroom_del);
	flushall();

	printf("Enter phone number to delete: ");
	scanf("%ld",&iphone_del);
	flushall();

	delete_check = delete_entry(iroom_del,iphone_del);

	if (delete_check == 0)
	{  gotoxy(1,25);
	   cprintf("Successful: There are presently %d entries in the database, ",total_entry);
	   cprintf("deleted %d.",del_entry);
	   getch();
	}
	if (delete_check == -1) 
	{  gotoxy(1,25);
	   cprintf("Error: The Room No./Phone No. Your looking for was Not Found.                  ");
	   getch();
	}

     }
     else
     if (option == '3')
     {  phone_found = 0;
	clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Find Room Number ##");

	gotoxy(1,6);
	printf("Enter the phone number to search for: ");
	scanf("%ld",&iphone_search);
	flushall(); 

	phone_check = find_phone_number(iphone_search);

	if (phone_check == 0)
	{  gotoxy(1,25);
	   cprintf("Successful: There are presently %d entries in the database, ",total_entry);

	   printf("found %d.",phone_found);
	   getch();
	}
	if (phone_check == -1) 
	{  gotoxy(1,25);
	   cprintf("Error: The Phone No. Your looking for was Not Found.");
	   getch();
	}
     }
     else
     if (option == '4')
     {  room_found = 0;
	clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Find Phone Number ##");

	gotoxy(1,6);
	printf("Enter the room number to search for: ");
	scanf("%d",&iroom_search);
	flushall();

	room_check = FindRoom(iroom_search);

	if (room_check == 0) 
	{  gotoxy(1,25);
	   cprintf("Successful: There are presently %d entries in the database, ",total_entry);
	   cprintf("found %d.",room_found);
	   getch();
	}
	if (room_check == -1) 
	{  gotoxy(1,25);
	   cprintf("Error: The Room No. Your looking for was Not Found.");
	   getch();
	}

     }
     else
     if (option == '5')
     {  clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## ListAll ##\n\n");

	list_check = ListAll();

	if (list_check == 0)
	{  gotoxy(1,25);
	   cprintf("List Sucuessful");
	   getch();
	}
	if (list_check == -1)
	{
	   gotoxy(1,25);
	   cprintf("Empty List");
	   getch();
	}
     }
     else
     if (option == '6')
     {  total_entries = GeTotalEntries();
	gotoxy(1,25);
	cprintf("There are presently %d entries stored in the Database.",total_entries);
	getch();
     }
     else
     if (option == '7') 
   {  clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Sort All Entries ##");
	gotoxy(1,6);
	printf("Press 'A' to sort database in [A]scending order");
	gotoxy(1,7);
	printf("Press 'D' to sort database in [D]escending order.");
	gotoxy(1,9);
	printf("Note: Database is sorted by phone no. entries.");
	sortopt = getch();
	flushall();

	sort_check = sort_entries(sortopt);
	getch();
	if (sort_check == 0)
	{  gotoxy(1,25);
	   cprintf("Database was successfully Sorted.                                      ");
	   getch();
	}
	if (sort_check == -1)
	{  gotoxy(1,25);
	   cprintf("Database was not sorted - Database is empty!");
	   getch();
	}
     }
     else
     if (option == '8') 
     {  clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Load Database ##");
	loaddatabase();
     }
     else
     if (option == '9')
     {  gotoxy(1,25);
	cprintf("Do you really want to exit?, Press 'Y' to confirm, anykey to cancel");
	exit_opt = getch();
	flushall();
	if (exit_opt == 'y' || exit_opt == 'Y')
	{  clrscr();
	   remakescreen();
	   screen_draw_flat();
	   gotoxy(1,4);
	   printf("## Exit To system ##\n\n");
	   menu_exit();
	}
     }
     else 
     {  gotoxy(1,25);
	cprintf("Error: Invalid option! Select an option between 1 and 9");
	getch();
	flushall();
     }
   }while  (option > '9' || option < '1' );
 }while (option != '`'); 
}