aboutsummaryrefslogtreecommitdiff
path: root/src/ext_distribution.cpp
blob: 81039bba60bd32b208597c8e009d319cb0d72b65 (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
#include "ext_packet.h"

#include "aoapplication.h"
#include "auth_flow.h"
#include "courtroom.h"
#include "networkmanager.h"

#include <QHeaderView>
#include <QVBoxLayout>

static void handleAuthChallenge(QByteArrayView body, AuthFlow *auth)
{
  if (!auth->awaiting_challenge())
  {
    return;
  }

  AuthChallenge challenge;
  if (!parseAuthChallenge(body, challenge))
  {
    qWarning() << "Invalid AuthChallenge message";
    return;
  }

  auth->respond(challenge);
}

void AOApplication::ex_message_received(QByteArrayView message)
{
  ExMsgType type = (ExMsgType)message[0];
  QByteArrayView body = message.sliced(1);
  switch (type)
  {
  case ExMsgType::auth_challenge:
    handleAuthChallenge(body, &this->auth);
    break;
  default:
    qWarning() << "Unknown message type:" << (int)type;
    break;
  }
}

void AOApplication::send_ex_message(const QByteArray &msg)
{
  // Why indirection?
  net_manager->ship_ex_message(msg);
}