Esempio n. 1
0
void SMOnlineRoom::SMOnlineParse(PacketFunctions &Packet, int clientnum) {
    int command = Packet.Read1();
    switch (command) {
    case 0:
        //Login
        break;
    case 1:
        //Change Room
    {
        int command = Packet.Read1();
        MString title = Packet.ReadNT();
        MString pw = Packet.ReadNT();
        ChangeRoom(command, title, clientnum, pw);
    }
    break;
    case 2:
        //Create new room
        if (m_allowgamerooms) {
            CreateRoom(Packet);
            ChangeRoom(1, m_joinrooms[m_joinrooms.size()-1]->GetTitle(), clientnum, "", true);
        }
        break;
    case 3:
        //Additional room info
        GenAdditionalInfo(Packet.ReadNT(), clientnum);
        break;
    default:
        LOG->Write(ssprintf("Invalid SMOnline command:%d", command));
        break;
    }
}
Esempio n. 2
0
void Menu::Draw(const sf::Event& ev){
	ChangeRoom(ev);
	if (ev.type == sf::Event::Resized){
		RepositionButtons();
		ResizeBackgrounds();
	}
	switch (mCurrentRoom){
	case MainMenu:{
		DrawMainMenu(ev);
		break;
	}
	case Library:{
		DrawLibrary(ev);
		break;
	}
	case About:{
		DrawAbout(ev);
		break;
	}
	}
};
Esempio n. 3
0
void SMOnlineRoom::AnalizeChat(unsigned int clientNum, PacketFunctions& Packet)
{
    MString message = Packet.ReadNT();
    ChatCommandPack ccp = ParseCommands(message, clientNum);

    switch(ccp.cmd)
    {
    case NONE:
        RelayChat(clientNum, message);
        return;
    case ANNOUNCE:
    {
        PacketFunctions reply;
        reply.ClearPacket();
        reply.Write1(NSCSU+NSServerOffset);
        reply.WriteNT(ccp.data.front());
        SERVER->SendToAll(reply);
    }
    return;
    case KICK:
    {
        const MString& name = ccp.data.front();
        for (unsigned int x = 0; x < m_clients.size(); ++x)
            for (unsigned int y = 0; y < m_clients[x]->GetNumPlayers(); ++y)
                if (m_clients[x]->GetPlayer(y)->GetName() == name)
                {
                    LOG->Write("Kicking " + name);
                    m_kicked[ccp.data.front()] = KickClient(name);
                    ChangeRoom(1, m_joinrooms[0]->GetTitle(), x, "", true);
                    return;
                }
    }
    break;
    case BAN:
    {
        const MString& name = ccp.data.front();
        for (unsigned int x = 0; x < m_clients.size(); ++x)
            for (unsigned int y = 0; y < m_clients[x]->GetNumPlayers(); ++y)
                if (m_clients[x]->GetPlayer(y)->GetName() == name)
                {
                    LOG->Write("Banning " + name);
                    m_banned[name] = name;
                    ChangeRoom(1, m_joinrooms[0]->GetTitle(), x, "", true);
                    return;
                }
    }
    break;
    case PM:
    {
        MString user = ccp.data.front();
        ccp.data.pop();
        MString message = ccp.data.front();
        MString tmp;
        MString success = "PM Failed!";

        if ((user.length() > 0) && (message.length() > 0))
        {
            tmp = "PM from ";
            unsigned int numPlayers = m_clients[m_cNum]->GetNumPlayers();
            for (unsigned int x = 0; x < numPlayers; ++x)
            {
                tmp += m_clients[m_cNum]->GetPlayerName(x);
                if ((numPlayers > 1) && (x < (numPlayers - 1)))
                    tmp += "&";
            }
            tmp += ": " + message;
            if (SERVER->MsgPlayer(user, tmp))
                success = "PM Success!";
        }
        PacketFunctions result;
        result.ClearPacket();
        result.Write1(NSCCM + NSServerOffset);
        result.WriteNT(success);
        m_clients[m_cNum]->SendData(result);
    }
    break;
    case DROP:
    {
        SMOnlineClient* tmp = SERVER->GetPlayerClient(ccp.data.front());
        if (tmp != NULL)
            tmp->connection.close();
    }
    break;
//	case FORCESTART:
//		break;
    default:
        break;
    };
}
Esempio n. 4
0
File: client.c Progetto: skony/sopy
int main(){
  
  int i,j=0;
  ownMSG = OwnMSGInit();
  printf("%d \n", ownMSG);
  SERVER_LIST_RESPONSE res = GetServerList();
  
  server_id = res.servers[0];
  printf("%d\n", server_id);
  sem_login_id = SemLoginInit();
  
  int login_res, change_res;
  while((login_res = Login()) != 201)
    if(login_res == 503){
      printf("server is too busy now...\n");
      sleep(5);
    }
    else if(login_res == 400)
	printf("your name is uncorrect\n");
      else if(login_res == 409)
	  printf("this name already exists\n");
  printf("Login successful! Hello %s\n", name);
  printf("If you first time use this program it's reccomended to try /help\n");
  int pid[2];/*
  if(fork() == 0){
    pid[0] = getpid();
    while(1)
      Heartbeat();
  }
  if(fork() == 0){
    pid[1] = getpid;
    while(1)
      ReceiveText();
  }*/
  char line[MAX_MSG_SIZE];
  while(1){
    printf(">>");
    fgets(line,MAX_MSG_SIZE, stdin);
    j = 0;
    while(line[j] != '\n') j++; 
    line[j] = '\0'; 
    if(strcmp(line, "/help") == 0)
      printf("/users../gusers../priv../logout../rooms../change..\n");
    else if(strcmp(line, "/users") == 0){ 
	CLIENT_LIST_RESPONSE* res = GetClientList();
	for(i=0; i<res->active_clients; i++)
	  printf("%s\n", res->names[i]);
      }
      else if(strcmp(line, "/gusers") == 0){ 
	  CLIENT_LIST_RESPONSE* res = GetGlobalClientList();
	  for(i=0; i<res->active_clients; i++)
	    printf("%s\n", res->names[i]);
	}
	else if(strcmp(line, "/priv") == 0)
	    PrivateText();
	  else if(strcmp(line, "/logout") == 0){
	      Logout();
	      kill(pid[0], 9); kill(pid[1], 9);
	    }
	    else if(strcmp(line, "/rooms") == 0){
		ROOM_LIST_RESPONSE* res = GetRoomList();
		for(i=0; i<res->active_rooms; i++)
		  printf("%s\n", res->rooms[i].name);
	      }
	      else if( (strcmp(line, "/change") == 0) ){
		  while(ChangeRoom() != 202)
		    printf("invalid room name\n");
		  printf("room change successful\n");
		}
		else
		  PublicText(line);
  }
  
  return 0;
}