Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
360498c8
Commit
360498c8
authored
Jul 03, 2015
by
Zach
Browse files
Merge pull request #1194 from ZeldaZach/fix_1192
Fix local mention crash
parents
bd633157
cc3e4edf
Changes
3
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/chatview.cpp
View file @
360498c8
...
...
@@ -298,59 +298,68 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
}
else
if
(
index
==
mentionFirstIndex
)
{
QMap
<
QString
,
UserListTWI
*>
userList
=
tabSupervisor
->
getUserListsTab
()
->
getAllUsersList
()
->
getUsers
();
if
(
tabSupervisor
->
getIsLocalGame
())
{
cursor
.
insertText
(
"@"
);
message
=
message
.
mid
(
1
);
}
else
{
int
firstSpace
=
message
.
indexOf
(
" "
);
QString
fullMentionUpToSpaceOrEnd
=
(
firstSpace
==
-
1
)
?
message
.
mid
(
1
)
:
message
.
mid
(
1
,
firstSpace
-
1
);
QString
mentionIntact
=
fullMentionUpToSpaceOrEnd
;
QMap
<
QString
,
UserListTWI
*>
userList
=
tabSupervisor
->
getUserListsTab
()
->
getAllUsersList
()
->
getUsers
();
while
(
fullMentionUpToSpaceOrEnd
.
size
())
{
if
(
isFullMentionAValidUser
(
userList
,
fullMentionUpToSpaceOrEnd
))
// Is there a user online named this?
int
firstSpace
=
message
.
indexOf
(
" "
);
QString
fullMentionUpToSpaceOrEnd
=
(
firstSpace
==
-
1
)
?
message
.
mid
(
1
)
:
message
.
mid
(
1
,
firstSpace
-
1
);
QString
mentionIntact
=
fullMentionUpToSpaceOrEnd
;
while
(
fullMentionUpToSpaceOrEnd
.
size
())
{
if
(
userName
.
toLower
()
==
fullMentionUpToSpaceOrEnd
.
toLower
(
))
// Is th
is
user
you
?
if
(
isFullMentionAValidUser
(
userList
,
fullMentionUpToSpaceOrEnd
))
// Is th
ere a
user
online named this
?
{
// You have received a valid mention!!
mentionFormat
.
setBackground
(
QBrush
(
getCustomMentionColor
()));
mentionFormat
.
setForeground
(
settingsCache
->
getChatMentionForeground
()
?
QBrush
(
Qt
::
white
)
:
QBrush
(
Qt
::
black
));
cursor
.
insertText
(
mention
,
mentionFormat
);
message
=
message
.
mid
(
mention
.
size
());
QApplication
::
alert
(
this
);
if
(
settingsCache
->
getShowMentionPopup
()
&&
shouldShowSystemPopup
())
if
(
userName
.
toLower
()
==
fullMentionUpToSpaceOrEnd
.
toLower
())
// Is this user you?
{
QString
ref
=
sender
.
left
(
sender
.
length
()
-
2
);
showSystemPopup
(
ref
);
// You have received a valid mention!!
mentionFormat
.
setBackground
(
QBrush
(
getCustomMentionColor
()));
mentionFormat
.
setForeground
(
settingsCache
->
getChatMentionForeground
()
?
QBrush
(
Qt
::
white
)
:
QBrush
(
Qt
::
black
));
cursor
.
insertText
(
mention
,
mentionFormat
);
message
=
message
.
mid
(
mention
.
size
());
QApplication
::
alert
(
this
);
if
(
settingsCache
->
getShowMentionPopup
()
&&
shouldShowSystemPopup
())
{
QString
ref
=
sender
.
left
(
sender
.
length
()
-
2
);
showSystemPopup
(
ref
);
}
}
else
{
QString
correctUserName
=
getNameFromUserList
(
userList
,
fullMentionUpToSpaceOrEnd
);
UserListTWI
*
vlu
=
userList
.
value
(
correctUserName
);
mentionFormatOtherUser
.
setAnchorHref
(
"user://"
+
QString
::
number
(
vlu
->
getUserInfo
().
user_level
())
+
"_"
+
correctUserName
);
cursor
.
insertText
(
"@"
+
correctUserName
,
mentionFormatOtherUser
);
message
=
message
.
mid
(
correctUserName
.
size
()
+
1
);
}
cursor
.
setCharFormat
(
defaultFormat
);
break
;
}
else
if
(
fullMentionUpToSpaceOrEnd
.
right
(
1
).
indexOf
(
notALetterOrNumber
)
==
-
1
)
{
cursor
.
insertText
(
"@"
+
mentionIntact
,
defaultFormat
);
message
=
message
.
mid
(
mentionIntact
.
size
()
+
1
);
cursor
.
setCharFormat
(
defaultFormat
);
break
;
}
else
{
QString
correctUserName
=
getNameFromUserList
(
userList
,
fullMentionUpToSpaceOrEnd
);
UserListTWI
*
vlu
=
userList
.
value
(
correctUserName
);
mentionFormatOtherUser
.
setAnchorHref
(
"user://"
+
QString
::
number
(
vlu
->
getUserInfo
().
user_level
())
+
"_"
+
correctUserName
);
cursor
.
insertText
(
"@"
+
correctUserName
,
mentionFormatOtherUser
);
message
=
message
.
mid
(
correctUserName
.
size
()
+
1
);
fullMentionUpToSpaceOrEnd
=
fullMentionUpToSpaceOrEnd
.
left
(
fullMentionUpToSpaceOrEnd
.
size
()
-
1
);
}
cursor
.
setCharFormat
(
defaultFormat
);
break
;
}
else
if
(
fullMentionUpToSpaceOrEnd
.
right
(
1
).
indexOf
(
notALetterOrNumber
)
==
-
1
)
{
cursor
.
insertText
(
"@"
+
mentionIntact
,
defaultFormat
);
message
=
message
.
mid
(
mentionIntact
.
size
()
+
1
);
cursor
.
setCharFormat
(
defaultFormat
);
break
;
}
else
{
fullMentionUpToSpaceOrEnd
=
fullMentionUpToSpaceOrEnd
.
left
(
fullMentionUpToSpaceOrEnd
.
size
()
-
1
);
}
}
}
else
{
message
=
message
.
mid
(
1
);
// Not certain when this would ever be reached, but just incase
message
=
message
.
mid
(
1
);
// Not certain when this would ever be reached, but just incase
lets skip the character
}
}
...
...
cockatrice/src/tab_supervisor.cpp
View file @
360498c8
...
...
@@ -184,6 +184,7 @@ int TabSupervisor::myAddTab(Tab *tab)
void
TabSupervisor
::
start
(
const
ServerInfo_User
&
_userInfo
)
{
isLocalGame
=
false
;
userInfo
=
new
ServerInfo_User
(
_userInfo
);
tabServer
=
new
TabServer
(
this
,
client
);
...
...
@@ -227,6 +228,7 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
tabDeckStorage
=
0
;
tabReplays
=
0
;
tabAdmin
=
0
;
isLocalGame
=
true
;
userInfo
=
new
ServerInfo_User
;
localClients
=
_clients
;
for
(
int
i
=
0
;
i
<
localClients
.
size
();
++
i
)
...
...
cockatrice/src/tab_supervisor.h
View file @
360498c8
...
...
@@ -60,6 +60,7 @@ private:
void
addCloseButtonToTab
(
Tab
*
tab
,
int
tabIndex
);
QString
sanitizeTabName
(
QString
dirty
)
const
;
QString
sanitizeHtml
(
QString
dirty
)
const
;
bool
isLocalGame
;
public:
TabSupervisor
(
AbstractClient
*
_client
,
QWidget
*
parent
=
0
);
~
TabSupervisor
();
...
...
@@ -67,6 +68,7 @@ public:
void
start
(
const
ServerInfo_User
&
userInfo
);
void
startLocal
(
const
QList
<
AbstractClient
*>
&
_clients
);
void
stop
();
bool
getIsLocalGame
()
const
{
return
isLocalGame
;
}
int
getGameCount
()
const
{
return
gameTabs
.
size
();
}
TabUserLists
*
getUserListsTab
()
const
{
return
tabUserLists
;
}
ServerInfo_User
*
getUserInfo
()
const
{
return
userInfo
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment