Skip to content

Commit

Permalink
updates for 'u' flag, stop sending 'p' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
silentwings authored and silentwings committed Feb 14, 2019
1 parent 12edf2c commit f323fcd
Show file tree
Hide file tree
Showing 21 changed files with 438 additions and 142 deletions.
3 changes: 2 additions & 1 deletion src/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BEGIN_EVENT_TABLE(Battle, wxEvtHandler)
EVT_TIMER(TIMER_ID, Battle::OnTimer)
END_EVENT_TABLE()

Battle::Battle(IServer& serv, int id)
Battle::Battle(IServer& serv, int id, std::string channel_name)
: m_auto_unspec(false)
, m_auto_unspec_num_players(0)
, m_autolaunch_game(true)
Expand All @@ -47,6 +47,7 @@ Battle::Battle(IServer& serv, int id)
{
m_autohost_manager = nullptr;
m_opts.battleid = m_id;
m_opts.channel_name = channel_name;
}


Expand Down
6 changes: 4 additions & 2 deletions src/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class wxTimer;
class Battle : public IBattle, public wxEvtHandler
{
public:
Battle(IServer& serv, int id);
Battle(IServer& serv, int id, std::string channel_name);
~Battle();

//const BattleOptions& opts() { return m_opts; }
Expand Down Expand Up @@ -141,9 +141,11 @@ class Battle : public IBattle, public wxEvtHandler
AutoHost m_ah;
bool m_autolock_on_start;

const int m_id;
wxTimer* m_timer;

const int m_id;
const std::string m_channel_name;

DECLARE_EVENT_TABLE()
};

Expand Down
10 changes: 10 additions & 0 deletions src/battlelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ void BattleList::RemoveBattle(battle_id_t const& id)
m_battles.erase(id);
}

BattleList::battle_id_t BattleList::BattleFromChannel(const std::string& channelName) const
{
for (auto el : m_battles)
{
IBattle* battle = el.second;
if (battle->GetChannelName() == channelName)
return battle->GetBattleId();
}
return -1;
}

BattleList::battle_map_t::size_type BattleList_Iter::GetNumBattles() const
{
Expand Down
5 changes: 3 additions & 2 deletions src/battlelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lsl/container/battlelist.h

class IBattle;

/** \brief encapsulates a <battle_id_t, Battle*> map
/** \brief encapsulates a write protected <battle_id_t, Battle*> map
*/
class BattleList
{
Expand All @@ -29,10 +29,11 @@ class BattleList
public:
BattleList();

typedef unsigned int battle_id_t;
typedef int battle_id_t; // a battle_id is unsigned, -1 used for 'not a battle'

void AddBattle(IBattle& battle);
void RemoveBattle(battle_id_t const& id);
battle_id_t BattleFromChannel(const std::string& channelName) const;

//! @brief mapping from battle id number to battle object
typedef std::map<battle_id_t, IBattle*> battle_map_t;
Expand Down
1 change: 1 addition & 0 deletions src/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Channel : public UserList, public SL::NonCopyable
std::string GetPassword() const;
void SetPassword(const std::string& pw);

std::set<std::string> user_list;
private:
IServer& m_serv;

Expand Down
14 changes: 14 additions & 0 deletions src/channellist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ bool ChannelList::ChannelExists(const std::string& name) const
return m_chans.find(name) != m_chans.end();
}

bool ChannelList::UserExists(const std::string& nick) const
{
for(auto p : m_chans)
{
Channel* channel = p.second;
if (channel->panel==nullptr)
continue;
if (channel->UserExists(nick))
return true;
}
return false;
}


channel_map_t::size_type ChannelList::GetNumChannels() const
{
return m_chans.size();
Expand Down
1 change: 1 addition & 0 deletions src/channellist.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ChannelList
Channel& GetChannel(const std::string& name);
Channel& GetChannel(channel_map_t::size_type index);
bool ChannelExists(const std::string& name) const;
bool UserExists(const std::string& nick) const;
channel_map_t::size_type GetNumChannels() const;

private:
Expand Down
22 changes: 14 additions & 8 deletions src/gui/chatpanelmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,21 @@ wxMenu* ChatPanelMenu::GetMenu()

void ChatPanelMenu::CreateNickListMenu()
{
User* user = m_chatpanel->GetSelectedUser();
bool bridge_user = false;
if (user!=nullptr && user->IsBridged())
bridge_user = true;

m_user_menu = new ChatPanelMenu::UserMenu(this, this);
if (m_chatpanel->m_type != CPT_User) {
if (m_chatpanel->m_type != CPT_User and !bridge_user) {
wxMenuItem* chatitem = new wxMenuItem(m_user_menu, CHAT_MENU_US_CHAT, _("Open Chat"), wxEmptyString, wxITEM_NORMAL);
m_user_menu->Append(chatitem);
}
wxMenuItem* joinbattleitem = new wxMenuItem(m_user_menu, CHAT_MENU_US_JOIN, _("Join same battle"), wxEmptyString, wxITEM_NORMAL);
m_user_menu->Append(joinbattleitem);

if (!bridge_user) {
wxMenuItem* joinbattleitem = new wxMenuItem(m_user_menu, CHAT_MENU_US_JOIN, _("Join same battle"), wxEmptyString, wxITEM_NORMAL);
m_user_menu->Append(joinbattleitem);
}

m_user_menu->AppendSeparator();
bool moderator = false;
try {
Expand Down Expand Up @@ -203,10 +210,9 @@ void ChatPanelMenu::CreateNickListMenu()
wxMenuItem* modringitem = new wxMenuItem(m_user_menu, CHAT_MENU_US_MODERATOR_RING, _("Ring"), wxEmptyString, wxITEM_NORMAL);
m_user_menu->Append(modringitem);
//m_user_menu->Append( -1, _("Moderator"), m_user_menu );
} else {
wxMenuItem* slapitem = new wxMenuItem(m_user_menu, CHAT_MENU_US_SLAP, _("Slap!"), wxEmptyString, wxITEM_NORMAL);
m_user_menu->Append(slapitem);
}
}
wxMenuItem* slapitem = new wxMenuItem(m_user_menu, CHAT_MENU_US_SLAP, _("Slap!"), wxEmptyString, wxITEM_NORMAL);
m_user_menu->Append(slapitem);

if (m_chatpanel->m_type != CPT_User) {
m_user_menu->AppendSeparator();
Expand Down
17 changes: 8 additions & 9 deletions src/gui/hosting/battleroomdataviewctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ void BattleroomDataViewCtrl::OnAllySelectEvent(wxCommandEvent& event)
int ally = event.GetId() - BATTLEROOM_VIEW_ALLY;

const User* user = GetSelectedItem();

if (user != nullptr) {
if (user != nullptr && !user->IsBridged()) {
m_Battle->ForceAlly(*const_cast<User*>(user), ally);
}
}
Expand All @@ -226,7 +225,7 @@ void BattleroomDataViewCtrl::OnTeamSelectEvent(wxCommandEvent& event)

const User* user = GetSelectedItem();

if (user != nullptr) {
if (user != nullptr && !user->IsBridged()) {
m_Battle->ForceTeam(*const_cast<User*>(user), team);
}
}
Expand Down Expand Up @@ -286,7 +285,7 @@ void BattleroomDataViewCtrl::OnColourSelect(wxCommandEvent& /*event*/)
{
const User* user = GetSelectedItem();

if (user == nullptr) {
if (user == nullptr || user->IsBridged()) {
return;
}

Expand All @@ -306,7 +305,7 @@ void BattleroomDataViewCtrl::OnSideSelect(wxCommandEvent& event)

const User* user = GetSelectedItem();

if (user != nullptr) {
if (user != nullptr && !user->IsBridged()) {
m_Battle->ForceSide(*const_cast<User*>(user), side);
}
}
Expand All @@ -315,7 +314,7 @@ void BattleroomDataViewCtrl::OnHandicapSelect(wxCommandEvent& /*event*/)
{
const User* user = GetSelectedItem();

if (user == nullptr) {
if (user == nullptr || user->IsBridged()) {
return;
}

Expand All @@ -329,7 +328,7 @@ void BattleroomDataViewCtrl::OnSpecSelect(wxCommandEvent& /*event*/)
{
const User* user = GetSelectedItem();

if (user != nullptr) {
if (user != nullptr && !user->IsBridged()) {
m_Battle->ForceSpectator(*const_cast<User*>(user), m_spec_item->IsChecked());
}
}
Expand All @@ -338,7 +337,7 @@ void BattleroomDataViewCtrl::OnKickPlayer(wxCommandEvent& /*event*/)
{
const User* user = GetSelectedItem();

if (user != nullptr) {
if (user != nullptr && !user->IsBridged()) {
m_Battle->KickPlayer(*const_cast<User*>(user));
}
}
Expand All @@ -347,7 +346,7 @@ void BattleroomDataViewCtrl::OnRingPlayer(wxCommandEvent& /*event*/)
{
const User* user = GetSelectedItem();

if (user != nullptr) {
if (user != nullptr && !user->IsBridged()) {
m_Battle->GetServer().Ring(user->GetNick());
}
}
Expand Down
55 changes: 45 additions & 10 deletions src/gui/hosting/battleroomdataviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ void BattleroomDataViewModel::GetValue(wxVariant& variant,
return;
}

bool isSpectator = user->BattleStatus().spectator;
bool isSpectator = user->BattleStatus().spectator || user->IsBridged();
bool isBot = user->BattleStatus().IsBot();
bool isBridged = user->IsBridged();

switch (col) {
case STATUS:
if (isBot) {
variant = wxVariant(iconsCollection->BMP_BOT);
} else if (isBridged) {
variant = wxVariant(iconsCollection->BMP_EMPTY);
} else {
if (GetBattle()->IsFounder(*user)) {
variant = wxVariant(iconsCollection->GetHostBmp(isSpectator));
Expand All @@ -69,7 +72,11 @@ void BattleroomDataViewModel::GetValue(wxVariant& variant,
break;

case INGAME:
variant = wxVariant(iconsCollection->GetUserListStateIcon(user->GetStatus(), false /*channel operator?*/, (user->GetBattle() != nullptr) /*in broom?*/));
if (isBridged) {
variant = wxVariant(iconsCollection->BMP_EMPTY);
} else {
variant = wxVariant(iconsCollection->GetUserListStateIcon(user->GetStatus(), false /*channel operator?*/, (user->GetBattle() != nullptr) /*in broom?*/));
}
break;

case FACTION:
Expand All @@ -90,15 +97,15 @@ void BattleroomDataViewModel::GetValue(wxVariant& variant,
break;

case COUNTRY:
if (isBot) {
if (isBot || isBridged) {
variant = wxVariant(iconsCollection->BMP_EMPTY);
} else {
variant = wxVariant(iconsCollection->GetFlagBmp(wxString(user->GetCountry())));
}
break;

case RANK:
if (isBot) {
if (isBot || isBridged) {
variant = wxVariant(iconsCollection->BMP_EMPTY);
} else {
variant = wxVariant(iconsCollection->GetRankBmp(user->GetRank()));
Expand All @@ -121,7 +128,7 @@ void BattleroomDataViewModel::GetValue(wxVariant& variant,
break;

case TRUESKILL:
if (user->GetTrueSkill() == 0) {
if (user->GetTrueSkill() == 0 || isBridged) {
variant = wxString(_T("-"));
} else {
variant = wxString::Format(_T("%ld"), std::lround(user->GetTrueSkill()));
Expand Down Expand Up @@ -197,6 +204,8 @@ int BattleroomDataViewModel::Compare(const wxDataViewItem& itemA,
status1 += 7;
if (userA->BattleStatus().spectator)
status1 += 10;
if (userA->IsBridged())
status1 += 50;
}

int status2 = 0;
Expand All @@ -209,6 +218,8 @@ int BattleroomDataViewModel::Compare(const wxDataViewItem& itemA,
status2 += 7;
if (userB->BattleStatus().spectator)
status2 += 10;
if (userB->IsBridged())
status2 += 50;
}

if (status1 < status2) {
Expand Down Expand Up @@ -293,7 +304,11 @@ int BattleroomDataViewModel::Compare(const wxDataViewItem& itemA,
} break;

case COUNTRY:
if (userA->GetCountry() < userB->GetCountry()) {
if (userA->IsBridged() && !userB->IsBridged()) {
sortingResult = 1;
} else if (!userA->IsBridged() && userB->IsBridged()) {
sortingResult = -1;
} else if (userA->GetCountry() < userB->GetCountry()) {
sortingResult = -1;
} else if (userA->GetCountry() > userB->GetCountry()) {
sortingResult = 1;
Expand All @@ -303,19 +318,35 @@ int BattleroomDataViewModel::Compare(const wxDataViewItem& itemA,
break;

case RANK:
sortingResult = (userA->GetRank() - userB->GetRank());
if (userA->IsBridged() && !userB->IsBridged()) {
sortingResult = 1;
} else if (!userA->IsBridged() && userB->IsBridged()) {
sortingResult = -1;
} else {
sortingResult = (userA->GetRank() - userB->GetRank());
}
break;

case NICKNAME:
sortingResult = BaseDataViewModel::Compare(itemA, itemB, column, true);
if (userA->IsBridged() && !userB->IsBridged()) {
sortingResult = 1;
} else if (!userA->IsBridged() && userB->IsBridged()) {
sortingResult = -1;
} else {
sortingResult = BaseDataViewModel::Compare(itemA, itemB, column, true);
}
break;

case TRUESKILL:
sortingResult = (userA->GetTrueSkill() - userB->GetTrueSkill());
break;

case TEAM:
if (userA->BattleStatus().spectator && (!userB->BattleStatus().spectator)) {
if (userA->IsBridged() && !userB->IsBridged()) {
sortingResult = 1;
} else if (!userA->IsBridged() && userB->IsBridged()) {
sortingResult = -1;
} else if (userA->BattleStatus().spectator && (!userB->BattleStatus().spectator)) {
return 1;
} else if (userB->BattleStatus().spectator && (!userA->BattleStatus().spectator)) {
return -1;
Expand All @@ -327,7 +358,11 @@ int BattleroomDataViewModel::Compare(const wxDataViewItem& itemA,
break;

case ALLY:
if (userA->BattleStatus().spectator && (!userB->BattleStatus().spectator)) {
if (userA->IsBridged() && !userB->IsBridged()) {
sortingResult = 1;
} else if (!userA->IsBridged() && userB->IsBridged()) {
sortingResult = -1;
} else if (userA->BattleStatus().spectator && (!userB->BattleStatus().spectator)) {
return 1;
} else if (userB->BattleStatus().spectator && (!userA->BattleStatus().spectator)) {
return -1;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ void MainWindow::OpenChannelChat(Channel& channel, bool doFocus)
//! @param nick The user to whom the chatwindow should be opened to
void MainWindow::OpenPrivateChat(User& user, bool doFocus)
{
if (user.IsBridged())
return;
ASSERT_LOGIC(m_chat_tab != 0, "m_chat_tab");
m_func_tabs->SetSelection(PAGE_CHAT);
ChatPanel* cp = m_chat_tab->AddChatPanel(user);
Expand Down
Loading

0 comments on commit f323fcd

Please sign in to comment.