summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/NetChat.cpp
blob: 044d96968664421ce9ee98d5e579d3b0c7a106f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Single chat message and sender
*/

#include "NetChat.h"
#include "NetLayer.h"

// +-------------------------------------------------------------------+

static int chat_id_key = 1000;

// +-------------------------------------------------------------------+

NetChatEntry::NetChatEntry(const NetUser* u, const char* s)
: id(chat_id_key++), msg(s)
{
    if (u) {
        user = u->Name();
        color = u->GetColor();
    }
    else {
        user = "unknown";
        color = Color::Gray;
    }

    time = NetLayer::GetUTC();
}

NetChatEntry::NetChatEntry(int msg_id, const char* u, const char* s)
: id(msg_id), user(u), msg(s)
{
    color = Color::Gray;
    time = NetLayer::GetUTC();

    if (id >= chat_id_key)
    chat_id_key = id + 1;
}

NetChatEntry::~NetChatEntry()
{ }