Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
chat.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
Protocol/ServerTypes.h
"
// MAX_ONLINEPLAYERS
4
5
#include <vector>
6
7
#define STORE_CHAT_SIZE 271
// includes 255 plus handle12, brackets2, colon1, space1
8
#define FORMAT_LINES 256
// controls how many we build for display in a vector, could be more because they are multi-line
9
10
class
CHATCHANNEL
11
{
12
public
:
13
unsigned
char
seqplayer
[
MAX_ONLINEPLAYERS
];
// sequential list of players
14
bool
dndplayer
[
MAX_ONLINEPLAYERS
];
15
short
players
;
16
17
void
AddPlayer
(
unsigned
char
tempplayer)
18
{
19
if
(
players
>=
MAX_ONLINEPLAYERS
)
20
return
;
// avoid buffer overflow
21
22
dndplayer
[
players
] =
false
;
// eventually retrieve this from the people manager persistent data
23
seqplayer
[
players
] = tempplayer;
24
players
++;
25
}
26
27
void
RemovePlayer
(
short
tempplayer)
28
{
29
if
(
players
<= 0)
30
return
;
31
32
short
index = -1;
33
for
(
short
t = 0; t <
players
; t++)
34
{
35
if
(
seqplayer
[t] == tempplayer)
36
{
37
index = t;
38
break
;
39
}
40
}
41
if
(index == -1)
42
return
;
43
44
for
(
short
t = index; t <
players
- 1; t++)
45
{
46
seqplayer
[t] =
seqplayer
[t + 1];
47
dndplayer
[t] =
dndplayer
[t + 1];
48
}
49
players
--;
50
}
51
52
// so we store all the chats as an array, one per element
53
std::vector<std::wstring>
chatline
;
54
std::vector<std::string>
chatlineplayer
;
55
// we go through that list to make another array that has chatlinereference or placeholder based on width
56
// ie |
57
// [reskin]: howdy doody fresh and fruity
58
// becomes
59
// [reskin]: howdy doody fresh
60
// BLANK LINE for and fruity
61
std::vector<std::wstring>
formatchatline
;
62
std::vector<std::string>
formatchatlineplayer
;
63
unsigned
char
channel
,
owner
;
// which channel does this tab transmit/receive on
64
bool
dnd
;
65
WCHAR
title
[
MAX_TAB_CHARS
- 5] = { 0 };
66
67
void
RefreshChat
(
long
columnWidth,
int
fontWidth)
68
{
69
if
(fontWidth <= 0)
70
return
;
71
72
const
size_t
maxChars =
RiseMath::Min
(
static_cast<
size_t
>
(columnWidth / fontWidth),
73
static_cast<
size_t
>
(
HELP_SIZE
- 1));
74
75
if
(maxChars == 0)
76
return
;
77
78
formatchatline
.clear();
79
formatchatlineplayer
.clear();
80
81
const
auto
totalLines =
chatline
.size();
82
const
auto
start =
static_cast<
size_t
>
(
RiseMath::Max
(0, (
int
)totalLines -
FORMAT_LINES
));
83
for
(
auto
pos = start; pos < totalLines; pos++)
// these are all the chat lines in the backlog
84
{
85
assert(pos <
chatlineplayer
.size());
86
formatchatlineplayer
.emplace_back(
chatlineplayer
.at(pos));
87
const
auto
& line =
chatline
.at(pos);
88
89
size_t
startIndex = 0;
90
do
91
{
92
if
(startIndex != 0)
formatchatlineplayer
.emplace_back(
""
);
93
std::basic_string<wchar_t> substr = line.substr(startIndex, maxChars);
94
if
(!substr.empty() && substr.at(0) == 32)
95
{
96
startIndex++;
97
substr = line.substr(startIndex, maxChars);
98
}
99
100
int
backup = 0;
101
const
size_t
length = substr.length();
102
if
(length == maxChars)
103
{
104
size_t
space = substr.find_last_of(L
' '
);
// npos
105
size_t
hyphen = substr.find_last_of(L
'-'
);
// 63
106
if
(space == std::string::npos) space = 0;
107
if
(hyphen == std::string::npos) hyphen = 0;
else
hyphen++;
108
backup = length -
RiseMath::Max
(space, hyphen);
// so 128 - 110 = 18 which is within 20
109
if
(backup > 20)
110
backup = 0;
111
}
112
113
formatchatline
.emplace_back(substr.substr(0, length - backup));
114
startIndex += maxChars - backup;
115
116
}
while
(startIndex < line.length());
117
}
118
}
119
120
CHATCHANNEL
()
121
{
122
channel
= 0;
123
owner
= 0;
124
players
= 0;
125
dnd
=
false
;
126
ZeroMemory(
seqplayer
,
MAX_ONLINEPLAYERS
);
127
ZeroMemory(
dndplayer
,
MAX_ONLINEPLAYERS
);
128
}
129
};
ServerTypes.h
MAX_ONLINEPLAYERS
#define MAX_ONLINEPLAYERS
Definition
ServerTypes.h:199
MAX_TAB_CHARS
#define MAX_TAB_CHARS
Definition
ServerTypes.h:204
FORMAT_LINES
#define FORMAT_LINES
Definition
chat.h:8
CHATCHANNEL::dndplayer
bool dndplayer[MAX_ONLINEPLAYERS]
Definition
chat.h:14
CHATCHANNEL::RemovePlayer
void RemovePlayer(short tempplayer)
Definition
chat.h:27
CHATCHANNEL::formatchatline
std::vector< std::wstring > formatchatline
Definition
chat.h:61
CHATCHANNEL::chatlineplayer
std::vector< std::string > chatlineplayer
Definition
chat.h:54
CHATCHANNEL::CHATCHANNEL
CHATCHANNEL()
Definition
chat.h:120
CHATCHANNEL::seqplayer
unsigned char seqplayer[MAX_ONLINEPLAYERS]
Definition
chat.h:13
CHATCHANNEL::players
short players
Definition
chat.h:15
CHATCHANNEL::formatchatlineplayer
std::vector< std::string > formatchatlineplayer
Definition
chat.h:62
CHATCHANNEL::chatline
std::vector< std::wstring > chatline
Definition
chat.h:53
CHATCHANNEL::owner
unsigned char owner
Definition
chat.h:63
CHATCHANNEL::RefreshChat
void RefreshChat(long columnWidth, int fontWidth)
Definition
chat.h:67
CHATCHANNEL::channel
unsigned char channel
Definition
chat.h:63
CHATCHANNEL::title
WCHAR title[MAX_TAB_CHARS - 5]
Definition
chat.h:65
CHATCHANNEL::AddPlayer
void AddPlayer(unsigned char tempplayer)
Definition
chat.h:17
CHATCHANNEL::dnd
bool dnd
Definition
chat.h:64
HELP_SIZE
#define HELP_SIZE
Definition
gui.h:21
RiseMath::Min
constexpr auto Min(A first, B second)
Definition
ClientMath.h:15
RiseMath::Max
constexpr auto Max(A first, B second)
Definition
ClientMath.h:16
chat.h
Generated on
for Rise by
1.18.0