summaryrefslogtreecommitdiff
path: root/src/core/sessionManager.hpp
blob: e84226c04d8608370be3177e9309c8ffff6d55cd (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
#pragma once

#include "../debug/format.hpp"
#include "../misc/memory.hpp"
#include "chatManager.hpp"
#include "session.hpp"
#include <thread>
#include <vector>

class CSessionManager {
  public:
	CSessionManager();
	~CSessionManager();

	void newSession();

	void run();
	void broadcast(const std::string &msg, std::optional<WP<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender
	void kick(WP<CSession> session, const bool kill = false, const std::string &reason = "");
	void addSession(const CSession &session);

	bool nameExists(const std::string &name);
	void shutdownSessions();

	SP<CSession>			  getByName(const std::string &name) const;
	SP<CSession>			  getByIp(const std::string &ip) const;
	std::vector<SP<CSession>> getSessions() const;

  private:
	void broadcast(const CChatManager::SMessage &msg) const;

	std::vector<std::pair<std::jthread, SP<CSession>>> m_vSessions;

	friend class CChatManager;
};
inline SP<CSessionManager> g_pSessionManager;