mirror of
https://github.com/PretendoNetwork/nex-protocols-common-go.git
synced 2025-04-02 11:02:13 -04:00
Compare commits
285 commits
Author | SHA1 | Date | |
---|---|---|---|
|
db917c2172 | ||
|
52d289e761 | ||
|
9005d07605 | ||
|
0fe4724b02 | ||
|
ffaba6e616 | ||
|
1450b7ffcc | ||
|
f83d9061ee | ||
|
59c7633654 | ||
|
63aaefe721 | ||
|
7781eb9e7b | ||
|
fa8845a22b | ||
|
7ba13e1abc | ||
|
2fd1f78759 | ||
|
426a8a81dc | ||
|
a01073f4e9 | ||
|
d5a4a74726 | ||
|
35aed21585 | ||
|
8084bcdf96 | ||
|
2b1d5b7c9b | ||
|
bcc53deac2 | ||
|
7f067a8ccd | ||
|
f9e65db077 | ||
|
5651e7f651 | ||
|
21fdc4730e | ||
|
d7f8b585c1 | ||
|
f7a2dab7cc | ||
|
9a67d7e82c | ||
|
9696be334e | ||
|
7b42e6a794 | ||
|
dd5156d92b | ||
|
e853c5df55 | ||
|
16ed5f16db | ||
|
b7042f3435 | ||
|
80765de633 | ||
|
0290f5c994 | ||
|
165afdc00d | ||
|
32a375d64e | ||
|
808a786461 | ||
|
69e3b1f342 | ||
|
32d393f708 | ||
|
ff20935c8c | ||
|
9639ab6c06 | ||
|
6953e78d24 | ||
|
dfe34baf48 | ||
|
8caa52cbbe | ||
|
14ae73e15e | ||
|
20f418e04f | ||
|
ed1f78ccfa | ||
|
9ccdfc9704 | ||
|
cc89c2ed3f | ||
|
03912fde5b | ||
|
54f171f298 | ||
|
e71f872ac1 | ||
|
98a2806b0c | ||
|
5ab8299563 | ||
|
e1957bbca9 | ||
|
06dc3fbc05 | ||
|
66a942a388 | ||
|
b169655951 | ||
|
785f021ffa | ||
|
3ca998f820 | ||
|
8e8e2bdbeb | ||
|
1fd823034b | ||
|
95a9481cc9 | ||
|
b782903fd9 | ||
|
d435690ad0 | ||
|
112d27947c | ||
|
dfe7dba66b | ||
|
67fb7c2dd3 | ||
|
e4fcbbbd97 | ||
|
469c77a247 | ||
|
68d4aa6873 | ||
|
8208e97bc2 | ||
|
656fa0fafb | ||
|
34f42e501d | ||
|
93a6c5d0f5 | ||
|
cef643aed0 | ||
|
a8cc302e32 | ||
|
3d22887dc8 | ||
|
4c2b1506be | ||
|
7f33824207 | ||
|
9ef1a27cf2 | ||
|
2728968441 | ||
|
87d7dc43b6 | ||
|
a97b74843a | ||
|
b6c8028476 | ||
|
410ca40c01 | ||
|
bbb4872e89 | ||
|
d15b82cc12 | ||
|
2f6d8445c6 | ||
|
ce83fe9720 | ||
|
33c6ccc225 | ||
|
6fab5521a7 | ||
|
6aa24a9ccf | ||
|
1a22244675 | ||
|
5168b5c3d4 | ||
|
bca1304ade | ||
|
2f18d58d87 | ||
|
a00ab245bf | ||
|
a5300196f8 | ||
|
365fe3f1e3 | ||
|
612033c7ee | ||
|
63102b9e20 | ||
|
aab72d6f17 | ||
|
c8ca7cab4a | ||
|
1836be6eb6 | ||
|
cf7a3ef105 | ||
|
f3f8c3b3e5 | ||
|
b03ebf8adb | ||
|
116149213d | ||
|
161f95da5f | ||
|
4162f6c9ac | ||
|
202487c7c7 | ||
|
5dd7310eda | ||
|
3ac05a7067 | ||
|
7e6bd47ff4 | ||
|
dc4ca3547b | ||
|
0e39f84cf9 | ||
|
045afaab5b | ||
|
edcc444a36 | ||
|
8acdf1c23d | ||
|
6404c51293 | ||
|
011d7a1753 | ||
|
2a06105c8d | ||
|
0df41b9a21 | ||
|
63149ad6f6 | ||
|
8095267d16 | ||
|
444944d57b | ||
|
271cc3fab2 | ||
|
9ed9b132e8 | ||
|
49bca9e60d | ||
|
890b9dc32a | ||
|
719cd89f70 | ||
|
4f97f68161 | ||
|
e143a8cc24 | ||
|
014ad34eea | ||
|
fc7039b169 | ||
|
cdfa4a68c3 | ||
|
3bbd382549 | ||
|
c3d36833d7 | ||
|
a2c1d4f704 | ||
|
b643ac5b31 | ||
|
823830b36c | ||
|
85ac1b29c1 | ||
|
cb8f1fb5c0 | ||
|
554491872c | ||
|
9953bced1b | ||
|
adec20f92c | ||
|
086c6017e0 | ||
|
738f1bf63a | ||
|
783d917ccc | ||
|
cfddbc4758 | ||
|
5160332968 | ||
|
363fe3cba5 | ||
|
2e542d846c | ||
|
942f04defd | ||
|
74e821b440 | ||
|
26f22bab45 | ||
|
76bb2e2818 | ||
|
aa73a77404 | ||
|
5903bbbd53 | ||
|
8358d71bc6 | ||
|
bb05a69934 | ||
|
3cdf7e4865 | ||
|
3b4ab59da4 | ||
|
f495b0b755 | ||
|
470f32c0de | ||
|
962aecdbd5 | ||
|
6b243dea56 | ||
|
d60b6b58ad | ||
|
5c006a0683 | ||
|
ca8ad16294 | ||
|
0e7243fb78 | ||
|
d33369f5bc | ||
|
c158b4f3b7 | ||
|
bcc5fc6e39 | ||
|
d2d3440e9d | ||
|
d9bb79bc0e | ||
|
eaecd44bbe | ||
|
07fa6d10c7 | ||
|
242bf55ff1 | ||
|
45027fb32f | ||
|
61960be5dc | ||
|
665c2b80db | ||
|
1a0be46eba | ||
|
b369cddadf | ||
|
1dc1b89c74 | ||
|
c033481f9b | ||
|
611a1146c5 | ||
|
2d4c8014a4 | ||
|
2aec134810 | ||
|
deae7db4c8 | ||
|
c34842ee0b | ||
|
8429e5ec77 | ||
|
cde148bf02 | ||
|
fe22fe4646 | ||
|
e3e9d1fa85 | ||
|
130669545d | ||
|
d2c568777b | ||
|
48ea32c4bd | ||
|
ef246842d4 | ||
|
1ff762db4e | ||
|
ea0e9a9e3c | ||
|
6fdfb063c1 | ||
|
ff41aad31a | ||
|
dc64652089 | ||
|
f75330649c | ||
|
1700e4e402 | ||
|
212370d13d | ||
|
155be71969 | ||
|
f900166ae2 | ||
|
87a101c568 | ||
|
71163070db | ||
|
807004e576 | ||
|
613f7a7a82 | ||
|
6a8807ee4a | ||
|
5b5b237027 | ||
|
d3e1504e17 | ||
|
70423fc875 | ||
|
fc68fbf5c3 | ||
|
d66db4e657 | ||
|
f3f84c3cbd | ||
|
5760221e74 | ||
|
9ec24f6297 | ||
|
41f4655e6d | ||
|
1421c488af | ||
|
5785c860f9 | ||
|
01db10686f | ||
|
b7e6c97f94 | ||
|
e6b3e0b842 | ||
|
0342dc2906 | ||
|
eaad0fcea8 | ||
|
ec12cfb374 | ||
|
c1dc70edfc | ||
|
6f5fbd94d5 | ||
|
e598334373 | ||
|
237060b9cb | ||
|
3e7d634b71 | ||
|
2e3bc892e8 | ||
|
7b54d5fa1d | ||
|
618b185517 | ||
|
3e7de77680 | ||
|
9f2d34a7ee | ||
|
46bc3e2bb4 | ||
|
9322a0ae3c | ||
|
175bbe4ede | ||
|
dfd3680156 | ||
|
8e5711cb38 | ||
|
4ebf815657 | ||
|
a89c9d3ac7 | ||
|
eee585960d | ||
|
468c4143af | ||
|
39ac779726 | ||
|
f2a32710a8 | ||
|
e3729c531a | ||
|
f5c2a38b94 | ||
|
24dfd6451e | ||
|
2170b0dc1f | ||
|
b61d65d389 | ||
|
4424b19205 | ||
|
ff19b6d446 | ||
|
dce7956806 | ||
|
994a11276b | ||
|
a28a4364d7 | ||
|
0627dc3d7e | ||
|
14ae2f317f | ||
|
574dd852ab | ||
|
b594be18f3 | ||
|
f84141fc31 | ||
|
abd27af2b2 | ||
|
9c79a8c7d4 | ||
|
323baf80fe | ||
|
483070aa38 | ||
|
8db897fb2c | ||
|
5a6480ec9e | ||
|
52542244b2 | ||
|
c45e1b0437 | ||
|
5d12089ca9 | ||
|
aa64381363 | ||
|
c1b7172d70 | ||
|
57048b3429 | ||
|
c1386ff993 | ||
|
4395175200 | ||
|
1872acfcd1 | ||
|
fcbcf79270 |
135 changed files with 9265 additions and 674 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -19,6 +19,12 @@
|
|||
|
||||
# Go workspace file
|
||||
go.work
|
||||
go.work.sum
|
||||
|
||||
# custom
|
||||
.vscode
|
||||
.vscode
|
||||
.env
|
||||
build
|
||||
log
|
||||
*.pem
|
||||
*.key
|
661
LICENSE
Normal file
661
LICENSE
Normal file
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
79
README.md
79
README.md
|
@ -1,2 +1,77 @@
|
|||
# nex-protocols-common-go
|
||||
Implementations of NEX protocols that are able to be used across all game servers.
|
||||
# NEX Protocols Common Go
|
||||
## NEX protocols used by many games with premade handlers and a high level API
|
||||
|
||||
[](https://godoc.org/github.com/PretendoNetwork/nex-protocols-common-go/v2)
|
||||
|
||||
### Other NEX libraries
|
||||
[nex-go](https://github.com/PretendoNetwork/nex-go) - Barebones NEX/PRUDP server implementation
|
||||
|
||||
[nex-protocols-go](https://github.com/PretendoNetwork/nex-protocols-go) - NEX protocol definitions
|
||||
|
||||
### Install
|
||||
|
||||
`go get github.com/PretendoNetwork/nex-protocols-common-go/v2`
|
||||
|
||||
### Usage
|
||||
|
||||
`nex-protocols-common-go` provides a higher level API than the [NEX Protocols Go module](https://github.com/PretendoNetwork/nex-protocols-go). This module handles many of the more common protcols and methods used shared by many servers. Instead of working directly with the NEX server, this module exposes an API for defining helper functions to provide the module with the data it needs to run
|
||||
|
||||
### Example, friends (Wii U) authentication server
|
||||
### For a complete example, see the complete [Friends Server](https://github.com/PretendoNetwork/friends), and other game servers
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting"
|
||||
common_ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/v2/ticket-granting"
|
||||
)
|
||||
|
||||
var nexServer *nex.PRUDPServer
|
||||
|
||||
func main() {
|
||||
nexServer := nex.NewPRUDPServer()
|
||||
|
||||
endpoint := nex.NewPRUDPEndPoint(1)
|
||||
endpoint.ServerAccount = nex.NewAccount(types.NewPID(1), "Quazal Authentication", "password"))
|
||||
endpoint.AccountDetailsByPID = accountDetailsByPID
|
||||
endpoint.AccountDetailsByUsername = accountDetailsByUsername
|
||||
|
||||
endpoint.OnData(func(packet nex.PacketInterface) {
|
||||
request := packet.RMCMessage()
|
||||
|
||||
fmt.Println("==Friends - Auth==")
|
||||
fmt.Printf("Protocol ID: %#v\n", request.ProtocolID)
|
||||
fmt.Printf("Method ID: %#v\n", request.MethodID)
|
||||
fmt.Println("==================")
|
||||
})
|
||||
|
||||
nexServer.SetFragmentSize(962)
|
||||
nexServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(1, 1, 0))
|
||||
nexServer.SessionKeyLength = 16
|
||||
nexServer.AccessKey = "ridfebb9"
|
||||
|
||||
ticketGrantingProtocol := ticket_granting.NewProtocol(endpoint)
|
||||
endpoint.RegisterServiceProtocol(ticketGrantingProtocol)
|
||||
commonTicketGrantingProtocol := common_ticket_granting.NewCommonProtocol(ticketGrantingProtocol)
|
||||
|
||||
secureStationURL := nex.NewStationURL("")
|
||||
secureStationURL.Scheme = "prudps"
|
||||
secureStationURL.Fields.Set("address", os.Getenv("SECURE_SERVER_LOCATION"))
|
||||
secureStationURL.Fields.Set("port", os.Getenv("SECURE_SERVER_PORT"))
|
||||
secureStationURL.Fields.Set("CID", "1")
|
||||
secureStationURL.Fields.Set("PID", "2")
|
||||
secureStationURL.Fields.Set("sid", "1")
|
||||
secureStationURL.Fields.Set("stream", "10")
|
||||
secureStationURL.Fields.Set("type", "2")
|
||||
|
||||
commonTicketGrantingProtocol.SecureStationURL = secureStationURL
|
||||
commonTicketGrantingProtocol.BuildName = "Pretendo Friends Auth"
|
||||
|
||||
nexServer.Listen(60000)
|
||||
}
|
||||
```
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
)
|
||||
|
||||
func generateTicket(userPID uint32, targetPID uint32) ([]byte, uint32) {
|
||||
if commonAuthenticationProtocol.passwordFromPIDHandler == nil {
|
||||
logger.Warning("Missing passwordFromPIDHandler!")
|
||||
return []byte{}, nex.Errors.Core.Unknown
|
||||
}
|
||||
|
||||
var userPassword string
|
||||
var targetPassword string
|
||||
var errorCode uint32
|
||||
|
||||
// TODO: Maybe we should error out if the user PID is the server account?
|
||||
switch userPID {
|
||||
case 2: // "Quazal Rendez-Vous" (the server user) account
|
||||
userPassword = commonAuthenticationProtocol.server.KerberosPassword()
|
||||
case 100: // guest user account
|
||||
userPassword = "MMQea3n!fsik"
|
||||
default:
|
||||
userPassword, errorCode = commonAuthenticationProtocol.passwordFromPIDHandler(userPID)
|
||||
}
|
||||
|
||||
if errorCode != 0 {
|
||||
return []byte{}, errorCode
|
||||
}
|
||||
|
||||
switch targetPID {
|
||||
case 2: // "Quazal Rendez-Vous" (the server user) account
|
||||
targetPassword = commonAuthenticationProtocol.server.KerberosPassword()
|
||||
case 100: // guest user account
|
||||
targetPassword = "MMQea3n!fsik"
|
||||
default:
|
||||
targetPassword, errorCode = commonAuthenticationProtocol.passwordFromPIDHandler(userPID)
|
||||
}
|
||||
|
||||
if errorCode != 0 {
|
||||
return []byte{}, errorCode
|
||||
}
|
||||
|
||||
userKey := nex.DeriveKerberosKey(userPID, []byte(userPassword))
|
||||
targetKey := nex.DeriveKerberosKey(targetPID, []byte(targetPassword))
|
||||
sessionKey := make([]byte, commonAuthenticationProtocol.server.KerberosKeySize())
|
||||
rand.Read(sessionKey)
|
||||
|
||||
ticketInternalData := nex.NewKerberosTicketInternalData()
|
||||
ticketInternalData.SetTimestamp(nex.NewDateTime(0)) // CHANGE THIS
|
||||
ticketInternalData.SetUserPID(userPID)
|
||||
ticketInternalData.SetSessionKey(sessionKey)
|
||||
encryptedTicketInternalData := ticketInternalData.Encrypt(targetKey, nex.NewStreamOut(commonAuthenticationProtocol.server))
|
||||
|
||||
ticket := nex.NewKerberosTicket()
|
||||
ticket.SetSessionKey(sessionKey)
|
||||
ticket.SetTargetPID(targetPID)
|
||||
ticket.SetInternalData(encryptedTicketInternalData)
|
||||
|
||||
return ticket.Encrypt(userKey, nex.NewStreamOut(commonAuthenticationProtocol.server)), 0
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
||||
)
|
||||
|
||||
func login(err error, client *nex.Client, callID uint32, username string) {
|
||||
var userPID uint32
|
||||
|
||||
if username == "guest" {
|
||||
userPID = 100
|
||||
} else {
|
||||
converted, err := strconv.Atoi(strings.TrimRight(username, "\x00"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
userPID = uint32(converted)
|
||||
}
|
||||
|
||||
var targetPID uint32 = 2 // "Quazal Rendez-Vous" (the server user) account PID
|
||||
|
||||
encryptedTicket, errorCode := generateTicket(userPID, targetPID)
|
||||
|
||||
rmcResponse := nex.NewRMCResponse(nexproto.AuthenticationProtocolID, callID)
|
||||
|
||||
if errorCode != 0 && errorCode != nex.Errors.RendezVous.InvalidUsername {
|
||||
// Some other error happened
|
||||
rmcResponse.SetError(errorCode)
|
||||
} else {
|
||||
var retval *nex.Result
|
||||
var pidPrincipal uint32
|
||||
var pbufResponse []byte
|
||||
var pConnectionData *nex.RVConnectionData
|
||||
var strReturnMsg string
|
||||
|
||||
pConnectionData = nex.NewRVConnectionData()
|
||||
pConnectionData.SetStationURL(commonAuthenticationProtocol.secureStationURL.EncodeToString())
|
||||
pConnectionData.SetSpecialProtocols([]byte{})
|
||||
pConnectionData.SetStationURLSpecialProtocols("")
|
||||
|
||||
/*
|
||||
From the wiki:
|
||||
|
||||
"If the username does not exist, the %retval% field is set to
|
||||
RendezVous::InvalidUsername and the other fields are left blank."
|
||||
*/
|
||||
if errorCode == nex.Errors.RendezVous.InvalidUsername {
|
||||
retval = nex.NewResultError(errorCode)
|
||||
} else {
|
||||
retval = nex.NewResultSuccess(nex.Errors.Core.Unknown)
|
||||
pidPrincipal = userPID
|
||||
pbufResponse = encryptedTicket
|
||||
strReturnMsg = commonAuthenticationProtocol.buildName
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewStreamOut(commonAuthenticationProtocol.server)
|
||||
|
||||
rmcResponseStream.WriteResult(retval)
|
||||
rmcResponseStream.WriteUInt32LE(pidPrincipal)
|
||||
rmcResponseStream.WriteBuffer(pbufResponse)
|
||||
rmcResponseStream.WriteStructure(pConnectionData)
|
||||
rmcResponseStream.WriteString(strReturnMsg)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse.SetSuccess(nexproto.AuthenticationMethodLogin, rmcResponseBody)
|
||||
}
|
||||
|
||||
rmcResponseBytes := rmcResponse.Bytes()
|
||||
|
||||
var responsePacket nex.PacketInterface
|
||||
|
||||
if commonAuthenticationProtocol.server.PrudpVersion() == 0 {
|
||||
responsePacket, _ = nex.NewPacketV0(client, nil)
|
||||
responsePacket.SetVersion(0)
|
||||
} else {
|
||||
responsePacket, _ = nex.NewPacketV1(client, nil)
|
||||
responsePacket.SetVersion(1)
|
||||
}
|
||||
|
||||
responsePacket.SetSource(0xA1)
|
||||
responsePacket.SetDestination(0xAF)
|
||||
responsePacket.SetType(nex.DataPacket)
|
||||
responsePacket.SetPayload(rmcResponseBytes)
|
||||
|
||||
responsePacket.AddFlag(nex.FlagNeedsAck)
|
||||
responsePacket.AddFlag(nex.FlagReliable)
|
||||
|
||||
commonAuthenticationProtocol.server.Send(responsePacket)
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
||||
"github.com/PretendoNetwork/plogger"
|
||||
)
|
||||
|
||||
var commonAuthenticationProtocol *CommonAuthenticationProtocol
|
||||
var logger = plogger.NewLogger()
|
||||
|
||||
type CommonAuthenticationProtocol struct {
|
||||
*nexproto.AuthenticationProtocol
|
||||
server *nex.Server
|
||||
secureStationURL *nex.StationURL
|
||||
buildName string
|
||||
passwordFromPIDHandler func(pid uint32) (string, uint32)
|
||||
}
|
||||
|
||||
func (commonAuthenticationProtocol *CommonAuthenticationProtocol) SetSecureStationURL(stationURL *nex.StationURL) {
|
||||
commonAuthenticationProtocol.secureStationURL = stationURL
|
||||
}
|
||||
|
||||
func (commonAuthenticationProtocol *CommonAuthenticationProtocol) SetBuildName(buildName string) {
|
||||
commonAuthenticationProtocol.buildName = buildName
|
||||
}
|
||||
|
||||
func (commonAuthenticationProtocol *CommonAuthenticationProtocol) SetPasswordFromPIDFunction(handler func(pid uint32) (string, uint32)) {
|
||||
commonAuthenticationProtocol.passwordFromPIDHandler = handler
|
||||
}
|
||||
|
||||
// NewCommonAuthenticationProtocol returns a new CommonAuthenticationProtocol
|
||||
func NewCommonAuthenticationProtocol(server *nex.Server) *CommonAuthenticationProtocol {
|
||||
authenticationProtocol := nexproto.NewAuthenticationProtocol(server)
|
||||
commonAuthenticationProtocol = &CommonAuthenticationProtocol{AuthenticationProtocol: authenticationProtocol, server: server}
|
||||
|
||||
commonAuthenticationProtocol.Login(login)
|
||||
commonAuthenticationProtocol.RequestTicket(requestTicket)
|
||||
|
||||
return commonAuthenticationProtocol
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package authentication
|
||||
|
||||
import (
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
||||
)
|
||||
|
||||
func requestTicket(err error, client *nex.Client, callID uint32, userPID uint32, targetPID uint32) {
|
||||
encryptedTicket, errorCode := generateTicket(userPID, targetPID)
|
||||
|
||||
rmcResponse := nex.NewRMCResponse(nexproto.AuthenticationProtocolID, callID)
|
||||
|
||||
// TODO:
|
||||
// If the source or target pid is invalid, the %retval% field is set to Core::AccessDenied and the ticket is empty.
|
||||
if errorCode != 0 {
|
||||
rmcResponse.SetError(errorCode)
|
||||
} else {
|
||||
rmcResponseStream := nex.NewStreamOut(commonAuthenticationProtocol.server)
|
||||
|
||||
rmcResponseStream.WriteResult(nex.NewResultSuccess(nex.Errors.Core.Unknown))
|
||||
rmcResponseStream.WriteBuffer(encryptedTicket)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse.SetSuccess(nexproto.AuthenticationMethodRequestTicket, rmcResponseBody)
|
||||
}
|
||||
|
||||
rmcResponseBytes := rmcResponse.Bytes()
|
||||
|
||||
var responsePacket nex.PacketInterface
|
||||
|
||||
if commonAuthenticationProtocol.server.PrudpVersion() == 0 {
|
||||
responsePacket, _ = nex.NewPacketV0(client, nil)
|
||||
responsePacket.SetVersion(0)
|
||||
} else {
|
||||
responsePacket, _ = nex.NewPacketV1(client, nil)
|
||||
responsePacket.SetVersion(1)
|
||||
}
|
||||
|
||||
responsePacket.SetSource(0xA1)
|
||||
responsePacket.SetDestination(0xAF)
|
||||
responsePacket.SetType(nex.DataPacket)
|
||||
responsePacket.SetPayload(rmcResponseBytes)
|
||||
|
||||
responsePacket.AddFlag(nex.FlagNeedsAck)
|
||||
responsePacket.AddFlag(nex.FlagReliable)
|
||||
|
||||
commonAuthenticationProtocol.server.Send(responsePacket)
|
||||
}
|
81
datastore/change_meta.go
Normal file
81
datastore/change_meta.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.UpdateObjectPeriodByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("UpdateObjectPeriodByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.UpdateObjectMetaBinaryByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("UpdateObjectMetaBinaryByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.UpdateObjectDataTypeByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("UpdateObjectDataTypeByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
metaInfo, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
// TODO - Is this the right permission?
|
||||
errCode = commonProtocol.VerifyObjectPermission(metaInfo.OwnerID, connection.PID(), metaInfo.DelPermission)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
if uint32(param.ModifiesFlag) & 0x08 != 0 {
|
||||
errCode = commonProtocol.UpdateObjectPeriodByDataIDWithPassword(param.DataID, param.Period, param.UpdatePassword)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
}
|
||||
|
||||
if uint32(param.ModifiesFlag) & 0x10 != 0 {
|
||||
errCode = commonProtocol.UpdateObjectMetaBinaryByDataIDWithPassword(param.DataID, param.MetaBinary, param.UpdatePassword)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
}
|
||||
|
||||
if uint32(param.ModifiesFlag) & 0x80 != 0 {
|
||||
errCode = commonProtocol.UpdateObjectDataTypeByDataIDWithPassword(param.DataID, param.DataType, param.UpdatePassword)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
}
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodChangeMeta
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterChangeMeta != nil {
|
||||
go commonProtocol.OnAfterChangeMeta(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
111
datastore/complete_post_object.go
Normal file
111
datastore/complete_post_object.go
Normal file
|
@ -0,0 +1,111 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.minIOClient == nil {
|
||||
common_globals.Logger.Warning("MinIOClient not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.GetObjectInfoByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.GetObjectOwnerByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectOwnerByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.GetObjectSizeByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectSizeByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.UpdateObjectUploadCompletedByDataID == nil {
|
||||
common_globals.Logger.Warning("UpdateObjectUploadCompletedByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.DeleteObjectByDataID == nil {
|
||||
common_globals.Logger.Warning("DeleteObjectByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
// * If GetObjectInfoByDataID returns data then that means
|
||||
// * the object has already been marked as uploaded. So do
|
||||
// * nothing
|
||||
_, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID)
|
||||
if errCode == nil {
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
// * Only allow an objects owner to make this request
|
||||
ownerPID, errCode := commonProtocol.GetObjectOwnerByDataID(param.DataID)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
if ownerPID != uint32(connection.PID()) {
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
bucket := commonProtocol.S3Bucket
|
||||
key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, param.DataID)
|
||||
|
||||
if param.IsSuccess {
|
||||
objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.NotFound, "change_error")
|
||||
}
|
||||
|
||||
objectSizeDB, errCode := commonProtocol.GetObjectSizeByDataID(param.DataID)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
if objectSizeS3 != uint64(objectSizeDB) {
|
||||
common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", param.DataID)
|
||||
// TODO - Is this a good error?
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
errCode = commonProtocol.UpdateObjectUploadCompletedByDataID(param.DataID, true)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
} else {
|
||||
errCode := commonProtocol.DeleteObjectByDataID(param.DataID)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
}
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodCompletePostObject
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterCompletePostObject != nil {
|
||||
go commonProtocol.OnAfterCompletePostObject(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
83
datastore/complete_post_objects.go
Normal file
83
datastore/complete_post_objects.go
Normal file
|
@ -0,0 +1,83 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.PacketInterface, callID uint32, dataIDs types.List[types.UInt64]) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.minIOClient == nil {
|
||||
common_globals.Logger.Warning("MinIOClient not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.GetObjectSizeByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectSizeByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.UpdateObjectUploadCompletedByDataID == nil {
|
||||
common_globals.Logger.Warning("UpdateObjectUploadCompletedByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
var errorCode *nex.Error
|
||||
|
||||
for _, dataID := range dataIDs {
|
||||
bucket := commonProtocol.S3Bucket
|
||||
key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, dataID)
|
||||
|
||||
objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
errorCode = nex.NewError(nex.ResultCodes.DataStore.NotFound, "change_error")
|
||||
break
|
||||
}
|
||||
|
||||
objectSizeDB, errCode := commonProtocol.GetObjectSizeByDataID(dataID)
|
||||
if errCode != nil {
|
||||
errorCode = errCode
|
||||
break
|
||||
}
|
||||
|
||||
if objectSizeS3 != uint64(objectSizeDB) {
|
||||
common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", dataID)
|
||||
// TODO - Is this a good error?
|
||||
errorCode = nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
break
|
||||
}
|
||||
|
||||
errCode = commonProtocol.UpdateObjectUploadCompletedByDataID(dataID, true)
|
||||
if errCode != nil {
|
||||
errorCode = errCode
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if errorCode != nil {
|
||||
return nil, errorCode
|
||||
}
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodCompletePostObjects
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterCompletePostObjects != nil {
|
||||
go commonProtocol.OnAfterCompletePostObjects(packet, dataIDs)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
54
datastore/delete_object.go
Normal file
54
datastore/delete_object.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) deleteObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.DeleteObjectByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("DeleteObjectByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
metaInfo, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
errCode = commonProtocol.VerifyObjectPermission(metaInfo.OwnerID, connection.PID(), metaInfo.DelPermission)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
errCode = commonProtocol.DeleteObjectByDataIDWithPassword(param.DataID, param.UpdatePassword)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodDeleteObject
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterDeleteObject != nil {
|
||||
go commonProtocol.OnAfterDeleteObject(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
66
datastore/get_meta.go
Normal file
66
datastore/get_meta.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.GetObjectInfoByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
var pMetaInfo datastore_types.DataStoreMetaInfo
|
||||
var errCode *nex.Error
|
||||
|
||||
// * Real server ignores PersistenceTarget if DataID is set
|
||||
if param.DataID == 0 {
|
||||
pMetaInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword)
|
||||
} else {
|
||||
pMetaInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword)
|
||||
}
|
||||
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
errCode = commonProtocol.VerifyObjectPermission(pMetaInfo.OwnerID, connection.PID(), pMetaInfo.Permission)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
pMetaInfo.FilterPropertiesByResultOption(param.ResultOption)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pMetaInfo.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodGetMeta
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetMeta != nil {
|
||||
go commonProtocol.OnAfterGetMeta(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
75
datastore/get_metas.go
Normal file
75
datastore/get_metas.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInterface, callID uint32, dataIDs types.List[types.UInt64], param datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
// TODO - Verify if param.PersistenceTarget is respected? It wouldn't make sense here but who knows
|
||||
|
||||
pMetaInfo := types.NewList[datastore_types.DataStoreMetaInfo]()
|
||||
pResults := types.NewList[types.QResult]()
|
||||
|
||||
// * param has an AccessPassword, but it goes unchecked here.
|
||||
// * The password would need to be the same for every object
|
||||
// * in the input array, which doesn't make any sense. Assuming
|
||||
// * it's unused until proven otherwise
|
||||
|
||||
for _, dataID := range dataIDs {
|
||||
objectInfo, errCode := commonProtocol.GetObjectInfoByDataID(dataID)
|
||||
|
||||
if errCode != nil {
|
||||
objectInfo = datastore_types.NewDataStoreMetaInfo()
|
||||
|
||||
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
|
||||
} else {
|
||||
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
|
||||
if errCode != nil {
|
||||
objectInfo = datastore_types.NewDataStoreMetaInfo()
|
||||
|
||||
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
|
||||
} else {
|
||||
pResults = append(pResults, types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown))
|
||||
}
|
||||
|
||||
objectInfo.FilterPropertiesByResultOption(param.ResultOption)
|
||||
}
|
||||
|
||||
pMetaInfo = append(pMetaInfo, objectInfo)
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pMetaInfo.WriteTo(rmcResponseStream)
|
||||
pResults.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodGetMetas
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetMetas != nil {
|
||||
go commonProtocol.OnAfterGetMetas(packet, dataIDs, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
81
datastore/get_metas_multiple_param.go
Normal file
81
datastore/get_metas_multiple_param.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet nex.PacketInterface, callID uint32, params types.List[datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.GetObjectInfoByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
pMetaInfo := types.NewList[datastore_types.DataStoreMetaInfo]()
|
||||
pResults := types.NewList[types.QResult]()
|
||||
|
||||
for _, param := range params {
|
||||
var objectInfo datastore_types.DataStoreMetaInfo
|
||||
var errCode *nex.Error
|
||||
|
||||
// * Real server ignores PersistenceTarget if DataID is set
|
||||
if param.DataID == 0 {
|
||||
objectInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword)
|
||||
} else {
|
||||
objectInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword)
|
||||
}
|
||||
|
||||
if errCode != nil {
|
||||
objectInfo = datastore_types.NewDataStoreMetaInfo()
|
||||
|
||||
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
|
||||
} else {
|
||||
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
|
||||
if errCode != nil {
|
||||
objectInfo = datastore_types.NewDataStoreMetaInfo()
|
||||
|
||||
pResults = append(pResults, types.NewQResultError(errCode.ResultCode))
|
||||
} else {
|
||||
pResults = append(pResults, types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown))
|
||||
}
|
||||
|
||||
objectInfo.FilterPropertiesByResultOption(param.ResultOption)
|
||||
}
|
||||
|
||||
pMetaInfo = append(pMetaInfo, objectInfo)
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pMetaInfo.WriteTo(rmcResponseStream)
|
||||
pResults.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodGetMetasMultipleParam
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetMetasMultipleParam != nil {
|
||||
go commonProtocol.OnAfterGetMetasMultipleParam(packet, params)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
72
datastore/post_meta_binary.go
Normal file
72
datastore/post_meta_binary.go
Normal file
|
@ -0,0 +1,72 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) {
|
||||
// * This method looks to function identically to DataStore::PreparePostObject,
|
||||
// * except the only difference being it doesn't return an S3 upload URL. This
|
||||
// * needs to be verified though, as there are other methods in the family such
|
||||
// * as DataStore::PostMetaBinaryWithDataID which make less sense in this context,
|
||||
// * unless those are just used to *update* a meta binary? Or maybe the DataID in
|
||||
// * those methods is a pre-allocated DataID from the server? Needs more testing
|
||||
|
||||
if commonProtocol.InitializeObjectByPreparePostParam == nil {
|
||||
common_globals.Logger.Warning("InitializeObjectByPreparePostParam not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.InitializeObjectRatingWithSlot == nil {
|
||||
common_globals.Logger.Warning("InitializeObjectRatingWithSlot not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
// TODO - Need to verify what param.PersistenceInitParam.DeleteLastObject really means. It's often set to true even when it wouldn't make sense
|
||||
dataID, errCode := commonProtocol.InitializeObjectByPreparePostParam(connection.PID(), param)
|
||||
if errCode != nil {
|
||||
common_globals.Logger.Errorf("Error code on object init: %s", errCode.Error())
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
// TODO - Should this be moved to InitializeObjectByPreparePostParam?
|
||||
for _ , ratingInitParamWithSlot := range param.RatingInitParams {
|
||||
errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot)
|
||||
if errCode != nil {
|
||||
common_globals.Logger.Errorf("Error code on rating init: %s", errCode.Error())
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
rmcResponseStream.WriteUInt64LE(dataID)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodPostMetaBinary
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterPostMetaBinary != nil {
|
||||
go commonProtocol.OnAfterPostMetaBinary(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
90
datastore/prepare_get_object.go
Normal file
90
datastore/prepare_get_object.go
Normal file
|
@ -0,0 +1,90 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
nex "github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByDataID == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataID not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.S3Presigner == nil {
|
||||
common_globals.Logger.Warning("S3Presigner not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
var objectInfo datastore_types.DataStoreMetaInfo
|
||||
var errCode *nex.Error
|
||||
|
||||
// * Real server ignores PersistenceTarget if DataID is set
|
||||
if param.DataID == 0 {
|
||||
objectInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword)
|
||||
} else {
|
||||
objectInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword)
|
||||
}
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
bucket := commonProtocol.S3Bucket
|
||||
key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, objectInfo.DataID)
|
||||
|
||||
url, err := commonProtocol.S3Presigner.GetObject(bucket, key, time.Minute*15)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.OperationNotAllowed, "change_error")
|
||||
}
|
||||
|
||||
requestHeaders, errCode := commonProtocol.S3GetRequestHeaders()
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
pReqGetInfo := datastore_types.NewDataStoreReqGetInfo()
|
||||
|
||||
pReqGetInfo.URL = types.NewString(url.String())
|
||||
pReqGetInfo.RequestHeaders = types.NewList[datastore_types.DataStoreKeyValue]()
|
||||
pReqGetInfo.Size = objectInfo.Size.Copy().(types.UInt32)
|
||||
pReqGetInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert)
|
||||
pReqGetInfo.DataID = param.DataID
|
||||
pReqGetInfo.RequestHeaders = requestHeaders
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pReqGetInfo.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodPrepareGetObject
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterPrepareGetObject != nil {
|
||||
go commonProtocol.OnAfterPrepareGetObject(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
105
datastore/prepare_post_object.go
Normal file
105
datastore/prepare_post_object.go
Normal file
|
@ -0,0 +1,105 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) preparePostObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.InitializeObjectByPreparePostParam == nil {
|
||||
common_globals.Logger.Warning("InitializeObjectByPreparePostParam not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.InitializeObjectRatingWithSlot == nil {
|
||||
common_globals.Logger.Warning("InitializeObjectRatingWithSlot not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.S3Presigner == nil {
|
||||
common_globals.Logger.Warning("S3Presigner not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
// TODO - Need to verify what param.PersistenceInitParam.DeleteLastObject really means. It's often set to true even when it wouldn't make sense
|
||||
dataID, errCode := commonProtocol.InitializeObjectByPreparePostParam(connection.PID(), param)
|
||||
if errCode != nil {
|
||||
common_globals.Logger.Errorf("Error on object init: %s", errCode.Error())
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
// TODO - Should this be moved to InitializeObjectByPreparePostParam?
|
||||
for _ , ratingInitParamWithSlot := range param.RatingInitParams {
|
||||
errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot)
|
||||
if errCode != nil {
|
||||
common_globals.Logger.Errorf("Error on rating init: %s", errCode.Error())
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
bucket := commonProtocol.S3Bucket
|
||||
key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, dataID)
|
||||
|
||||
URL, formData, err := commonProtocol.S3Presigner.PostObject(bucket, key, time.Minute*15)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.OperationNotAllowed, "change_error")
|
||||
}
|
||||
|
||||
requestHeaders, errCode := commonProtocol.S3PostRequestHeaders()
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
pReqPostInfo := datastore_types.NewDataStoreReqPostInfo()
|
||||
|
||||
pReqPostInfo.DataID = types.NewUInt64(dataID)
|
||||
pReqPostInfo.URL = types.NewString(URL.String())
|
||||
pReqPostInfo.RequestHeaders = types.NewList[datastore_types.DataStoreKeyValue]()
|
||||
pReqPostInfo.FormFields = types.NewList[datastore_types.DataStoreKeyValue]()
|
||||
pReqPostInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert)
|
||||
pReqPostInfo.RequestHeaders = requestHeaders
|
||||
|
||||
for key, value := range formData {
|
||||
field := datastore_types.NewDataStoreKeyValue()
|
||||
field.Key = types.NewString(key)
|
||||
field.Value = types.NewString(value)
|
||||
|
||||
pReqPostInfo.FormFields = append(pReqPostInfo.FormFields, field)
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pReqPostInfo.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodPreparePostObject
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterPreparePostObject != nil {
|
||||
go commonProtocol.OnAfterPreparePostObject(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
163
datastore/protocol.go
Normal file
163
datastore/protocol.go
Normal file
|
@ -0,0 +1,163 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
type CommonProtocol struct {
|
||||
endpoint nex.EndpointInterface
|
||||
protocol datastore.Interface
|
||||
S3Bucket string
|
||||
s3DataKeyBase string
|
||||
s3NotifyKeyBase string
|
||||
RootCACert []byte
|
||||
minIOClient *minio.Client
|
||||
S3Presigner S3PresignerInterface
|
||||
GetUserFriendPIDs func(pid uint32) []uint32
|
||||
GetObjectInfoByDataID func(dataID types.UInt64) (datastore_types.DataStoreMetaInfo, *nex.Error)
|
||||
UpdateObjectPeriodByDataIDWithPassword func(dataID types.UInt64, dataType types.UInt16, password types.UInt64) *nex.Error
|
||||
UpdateObjectMetaBinaryByDataIDWithPassword func(dataID types.UInt64, metaBinary types.QBuffer, password types.UInt64) *nex.Error
|
||||
UpdateObjectDataTypeByDataIDWithPassword func(dataID types.UInt64, period types.UInt16, password types.UInt64) *nex.Error
|
||||
GetObjectSizeByDataID func(dataID types.UInt64) (uint32, *nex.Error)
|
||||
UpdateObjectUploadCompletedByDataID func(dataID types.UInt64, uploadCompleted bool) *nex.Error
|
||||
GetObjectInfoByPersistenceTargetWithPassword func(persistenceTarget datastore_types.DataStorePersistenceTarget, password types.UInt64) (datastore_types.DataStoreMetaInfo, *nex.Error)
|
||||
GetObjectInfoByDataIDWithPassword func(dataID types.UInt64, password types.UInt64) (datastore_types.DataStoreMetaInfo, *nex.Error)
|
||||
S3GetRequestHeaders func() ([]datastore_types.DataStoreKeyValue, *nex.Error)
|
||||
S3PostRequestHeaders func() ([]datastore_types.DataStoreKeyValue, *nex.Error)
|
||||
InitializeObjectByPreparePostParam func(ownerPID types.PID, param datastore_types.DataStorePreparePostParam) (uint64, *nex.Error)
|
||||
InitializeObjectRatingWithSlot func(dataID uint64, param datastore_types.DataStoreRatingInitParamWithSlot) *nex.Error
|
||||
RateObjectWithPassword func(dataID types.UInt64, slot types.UInt8, ratingValue types.Int32, accessPassword types.UInt64) (datastore_types.DataStoreRatingInfo, *nex.Error)
|
||||
DeleteObjectByDataIDWithPassword func(dataID types.UInt64, password types.UInt64) *nex.Error
|
||||
DeleteObjectByDataID func(dataID types.UInt64) *nex.Error
|
||||
GetObjectInfosByDataStoreSearchParam func(param datastore_types.DataStoreSearchParam, pid types.PID) ([]datastore_types.DataStoreMetaInfo, uint32, *nex.Error)
|
||||
GetObjectOwnerByDataID func(dataID types.UInt64) (uint32, *nex.Error)
|
||||
OnAfterDeleteObject func(packet nex.PacketInterface, param datastore_types.DataStoreDeleteParam)
|
||||
OnAfterGetMeta func(packet nex.PacketInterface, param datastore_types.DataStoreGetMetaParam)
|
||||
OnAfterGetMetas func(packet nex.PacketInterface, dataIDs types.List[types.UInt64], param datastore_types.DataStoreGetMetaParam)
|
||||
OnAfterSearchObject func(packet nex.PacketInterface, param datastore_types.DataStoreSearchParam)
|
||||
OnAfterRateObject func(packet nex.PacketInterface, target datastore_types.DataStoreRatingTarget, param datastore_types.DataStoreRateObjectParam, fetchRatings types.Bool)
|
||||
OnAfterPostMetaBinary func(packet nex.PacketInterface, param datastore_types.DataStorePreparePostParam)
|
||||
OnAfterPreparePostObject func(packet nex.PacketInterface, param datastore_types.DataStorePreparePostParam)
|
||||
OnAfterPrepareGetObject func(packet nex.PacketInterface, param datastore_types.DataStorePrepareGetParam)
|
||||
OnAfterCompletePostObject func(packet nex.PacketInterface, param datastore_types.DataStoreCompletePostParam)
|
||||
OnAfterGetMetasMultipleParam func(packet nex.PacketInterface, params types.List[datastore_types.DataStoreGetMetaParam])
|
||||
OnAfterCompletePostObjects func(packet nex.PacketInterface, dataIDs types.List[types.UInt64])
|
||||
OnAfterChangeMeta func(packet nex.PacketInterface, param datastore_types.DataStoreChangeMetaParam)
|
||||
OnAfterRateObjects func(packet nex.PacketInterface, targets types.List[datastore_types.DataStoreRatingTarget], params types.List[datastore_types.DataStoreRateObjectParam], transactional types.Bool, fetchRatings types.Bool)
|
||||
}
|
||||
|
||||
func (c *CommonProtocol) S3StatObject(bucket, key string) (minio.ObjectInfo, error) {
|
||||
return c.minIOClient.StatObject(context.TODO(), bucket, key, minio.StatObjectOptions{})
|
||||
}
|
||||
|
||||
func (c *CommonProtocol) S3ObjectSize(bucket, key string) (uint64, error) {
|
||||
info, err := c.S3StatObject(bucket, key)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return uint64(info.Size), nil
|
||||
}
|
||||
|
||||
func (c *CommonProtocol) VerifyObjectPermission(ownerPID, accessorPID types.PID, permission datastore_types.DataStorePermission) *nex.Error {
|
||||
if permission.Permission > 3 {
|
||||
return nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
// * Owner can always access their own objects
|
||||
if ownerPID.Equals(accessorPID) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// * Allow anyone
|
||||
if permission.Permission == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// * Allow only friends of the owner
|
||||
if permission.Permission == 1 {
|
||||
// TODO - This assumes a legacy client. Will not work on the Switch
|
||||
friendsList := c.GetUserFriendPIDs(uint32(ownerPID))
|
||||
|
||||
if !slices.Contains(friendsList, uint32(accessorPID)) {
|
||||
return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
// * Allow only users whose PIDs are defined in permission.RecipientIDs
|
||||
if permission.Permission == 2 {
|
||||
if !permission.RecipientIDs.Contains(accessorPID) {
|
||||
return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
// * Allow only the owner
|
||||
if permission.Permission == 3 {
|
||||
if !ownerPID.Equals(accessorPID) {
|
||||
return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDataKeyBase sets the base for the key to be used when uploading standard DataStore objects
|
||||
func (c *CommonProtocol) SetDataKeyBase(base string) {
|
||||
// * Just in case someone passes a badly formatted key
|
||||
base = strings.TrimPrefix(base, "/")
|
||||
base = strings.TrimSuffix(base, "/")
|
||||
c.s3DataKeyBase = base
|
||||
}
|
||||
|
||||
// SetNotifyKeyBase sets the base for the key to be used when uploading DataStore notification data
|
||||
func (c *CommonProtocol) SetNotifyKeyBase(base string) {
|
||||
// * Just in case someone passes a badly formatted key
|
||||
base = strings.TrimPrefix(base, "/")
|
||||
base = strings.TrimSuffix(base, "/")
|
||||
c.s3NotifyKeyBase = base
|
||||
}
|
||||
|
||||
// SetMinIOClient sets the MinIO S3 client
|
||||
func (c *CommonProtocol) SetMinIOClient(client *minio.Client) {
|
||||
c.minIOClient = client
|
||||
c.S3Presigner = NewS3Presigner(c.minIOClient)
|
||||
}
|
||||
|
||||
// NewCommonProtocol returns a new CommonProtocol
|
||||
func NewCommonProtocol(protocol datastore.Interface) *CommonProtocol {
|
||||
commonProtocol := &CommonProtocol{
|
||||
endpoint: protocol.Endpoint(),
|
||||
protocol: protocol,
|
||||
RootCACert: []byte{},
|
||||
S3GetRequestHeaders: func() ([]datastore_types.DataStoreKeyValue, *nex.Error) {
|
||||
return []datastore_types.DataStoreKeyValue{}, nil
|
||||
},
|
||||
S3PostRequestHeaders: func() ([]datastore_types.DataStoreKeyValue, *nex.Error) {
|
||||
return []datastore_types.DataStoreKeyValue{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
protocol.SetHandlerDeleteObject(commonProtocol.deleteObject)
|
||||
protocol.SetHandlerGetMeta(commonProtocol.getMeta)
|
||||
protocol.SetHandlerGetMetas(commonProtocol.getMetas)
|
||||
protocol.SetHandlerSearchObject(commonProtocol.searchObject)
|
||||
protocol.SetHandlerRateObject(commonProtocol.rateObject)
|
||||
protocol.SetHandlerPostMetaBinary(commonProtocol.postMetaBinary)
|
||||
protocol.SetHandlerPreparePostObject(commonProtocol.preparePostObject)
|
||||
protocol.SetHandlerPrepareGetObject(commonProtocol.prepareGetObject)
|
||||
protocol.SetHandlerCompletePostObject(commonProtocol.completePostObject)
|
||||
protocol.SetHandlerGetMetasMultipleParam(commonProtocol.getMetasMultipleParam)
|
||||
protocol.SetHandlerCompletePostObjects(commonProtocol.completePostObjects)
|
||||
protocol.SetHandlerChangeMeta(commonProtocol.changeMeta)
|
||||
protocol.SetHandlerRateObjects(commonProtocol.rateObjects)
|
||||
|
||||
return commonProtocol
|
||||
}
|
69
datastore/rate_object.go
Normal file
69
datastore/rate_object.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) rateObject(err error, packet nex.PacketInterface, callID uint32, target datastore_types.DataStoreRatingTarget, param datastore_types.DataStoreRateObjectParam, fetchRatings types.Bool) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.RateObjectWithPassword == nil {
|
||||
common_globals.Logger.Warning("RateObjectWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
objectInfo, errCode := commonProtocol.GetObjectInfoByDataIDWithPassword(target.DataID, param.AccessPassword)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
pRating, errCode := commonProtocol.RateObjectWithPassword(target.DataID, target.Slot, param.RatingValue, param.AccessPassword)
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
// * This is kinda backwards. Server returns
|
||||
// * the rating by default, so we check if
|
||||
// * the client DOESN'T want it and then just
|
||||
// * zero it out
|
||||
if !fetchRatings {
|
||||
pRating = datastore_types.NewDataStoreRatingInfo()
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pRating.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodRateObject
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterRateObject != nil {
|
||||
go commonProtocol.OnAfterRateObject(packet, target, param, fetchRatings)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
91
datastore/rate_objects.go
Normal file
91
datastore/rate_objects.go
Normal file
|
@ -0,0 +1,91 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) rateObjects(err error, packet nex.PacketInterface, callID uint32, targets types.List[datastore_types.DataStoreRatingTarget], params types.List[datastore_types.DataStoreRateObjectParam], transactional types.Bool, fetchRatings types.Bool) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfoByDataIDWithPassword == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if commonProtocol.RateObjectWithPassword == nil {
|
||||
common_globals.Logger.Warning("RateObjectWithPassword not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
pRatings := types.NewList[datastore_types.DataStoreRatingInfo]()
|
||||
pResults := types.NewList[types.QResult]()
|
||||
|
||||
// * Real DataStore does not actually check this.
|
||||
// * I just didn't feel like working out the
|
||||
// * logic for differing sized lists. So force
|
||||
// * them to always be the same
|
||||
if len(targets) != len(params) {
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
var errorCode *nex.Error
|
||||
|
||||
for i, target := range targets {
|
||||
// * We already checked that targets and params will have the same length
|
||||
param := params[i]
|
||||
|
||||
objectInfo, errCode := commonProtocol.GetObjectInfoByDataIDWithPassword(target.DataID, param.AccessPassword)
|
||||
if errCode != nil {
|
||||
errorCode = errCode
|
||||
break
|
||||
}
|
||||
|
||||
errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission)
|
||||
if errCode != nil {
|
||||
errorCode = errCode
|
||||
break
|
||||
}
|
||||
|
||||
rating, errCode := commonProtocol.RateObjectWithPassword(target.DataID, target.Slot, param.RatingValue, param.AccessPassword)
|
||||
if errCode != nil {
|
||||
errorCode = errCode
|
||||
break
|
||||
}
|
||||
|
||||
if fetchRatings {
|
||||
pRatings = append(pRatings, rating)
|
||||
}
|
||||
}
|
||||
|
||||
if errorCode != nil {
|
||||
return nil, errorCode
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pRatings.WriteTo(rmcResponseStream)
|
||||
pResults.WriteTo(rmcResponseStream) // * pResults is ALWAYS empty in SMM?
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodRateObjects
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterRateObjects != nil {
|
||||
go commonProtocol.OnAfterRateObjects(packet, targets, params, transactional, fetchRatings)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
51
datastore/s3_presigner.go
Normal file
51
datastore/s3_presigner.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
type S3PresignerInterface interface {
|
||||
GetObject(bucket, key string, lifetime time.Duration) (*url.URL, error)
|
||||
PostObject(bucket, key string, lifetime time.Duration) (*url.URL, map[string]string, error)
|
||||
}
|
||||
|
||||
type S3Presigner struct {
|
||||
minio *minio.Client
|
||||
}
|
||||
|
||||
func (p *S3Presigner) GetObject(bucket, key string, lifetime time.Duration) (*url.URL, error) {
|
||||
reqParams := make(url.Values)
|
||||
|
||||
return p.minio.PresignedGetObject(context.Background(), bucket, key, lifetime, reqParams)
|
||||
}
|
||||
|
||||
func (p *S3Presigner) PostObject(bucket, key string, lifetime time.Duration) (*url.URL, map[string]string, error) {
|
||||
policy := minio.NewPostPolicy()
|
||||
|
||||
err := policy.SetBucket(bucket)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = policy.SetKey(key)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = policy.SetExpires(time.Now().UTC().Add(lifetime).UTC())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return p.minio.PresignedPostPolicy(context.Background(), policy)
|
||||
}
|
||||
|
||||
func NewS3Presigner(minioClient *minio.Client) *S3Presigner {
|
||||
return &S3Presigner{
|
||||
minio: minioClient,
|
||||
}
|
||||
}
|
97
datastore/search_object.go
Normal file
97
datastore/search_object.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore"
|
||||
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketInterface, callID uint32, param datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.GetObjectInfosByDataStoreSearchParam == nil {
|
||||
common_globals.Logger.Warning("GetObjectInfosByDataStoreSearchParam not defined")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender()
|
||||
endpoint := connection.Endpoint()
|
||||
|
||||
// * This is likely game-specific. Also developer note:
|
||||
// * Please keep in mind that no results is allowed. errCode
|
||||
// * should NEVER be DataStore::NotFound!
|
||||
// *
|
||||
// * DataStoreSearchParam contains a ResultRange to limit the
|
||||
// * returned results. TotalCount is the total matching objects
|
||||
// * in the database, whereas objects is the limited results
|
||||
objects, totalCount, errCode := commonProtocol.GetObjectInfosByDataStoreSearchParam(param, connection.PID())
|
||||
if errCode != nil {
|
||||
return nil, errCode
|
||||
}
|
||||
|
||||
pSearchResult := datastore_types.NewDataStoreSearchResult()
|
||||
|
||||
pSearchResult.Result = types.NewList[datastore_types.DataStoreMetaInfo]()
|
||||
|
||||
for _, object := range objects {
|
||||
errCode = commonProtocol.VerifyObjectPermission(object.OwnerID, connection.PID(), object.Permission)
|
||||
if errCode != nil {
|
||||
// * Since we don't error here, should we also
|
||||
// * "hide" these results by also decrementing
|
||||
// * totalCount?
|
||||
continue
|
||||
}
|
||||
|
||||
object.FilterPropertiesByResultOption(param.ResultOption)
|
||||
|
||||
pSearchResult.Result = append(pSearchResult.Result, object)
|
||||
}
|
||||
|
||||
var totalCountType uint8
|
||||
|
||||
// * Doing this here since the object
|
||||
// * the permissions checks in the
|
||||
// * previous loop will mutate the data
|
||||
// * returned from the database
|
||||
if totalCount == uint32(len(pSearchResult.Result)) {
|
||||
totalCountType = 0 // * Has no more data. All possible results were returned
|
||||
} else {
|
||||
totalCountType = 1 // * Has more data. Not all possible results were returned
|
||||
}
|
||||
|
||||
// * Disables the TotalCount
|
||||
// *
|
||||
// * Only seen in struct revision 3 or
|
||||
// * NEX 4.0+
|
||||
if param.StructureVersion >= 3 || endpoint.LibraryVersions().DataStore.GreaterOrEqual("4.0.0") {
|
||||
if !param.TotalCountEnabled {
|
||||
totalCount = 0
|
||||
totalCountType = 3
|
||||
}
|
||||
}
|
||||
|
||||
pSearchResult.TotalCount = types.NewUInt32(totalCount)
|
||||
pSearchResult.TotalCountType = types.NewUInt8(totalCountType)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
pSearchResult.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = datastore.ProtocolID
|
||||
rmcResponse.MethodID = datastore.MethodSearchObject
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterSearchObject != nil {
|
||||
go commonProtocol.OnAfterSearchObject(packet, param)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
7
globals/globals.go
Normal file
7
globals/globals.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package common_globals
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/plogger-go"
|
||||
)
|
||||
|
||||
var Logger = plogger.NewLogger()
|
27
globals/matchmaking_globals.go
Normal file
27
globals/matchmaking_globals.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package common_globals
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sync"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
)
|
||||
|
||||
// MatchmakingManager manages a matchmaking instance
|
||||
type MatchmakingManager struct {
|
||||
Database *sql.DB
|
||||
Endpoint *nex.PRUDPEndPoint
|
||||
Mutex *sync.RWMutex
|
||||
GetUserFriendPIDs func(pid uint32) []uint32
|
||||
GetDetailedGatheringByID func(manager *MatchmakingManager, sourcePID uint64, gatheringID uint32) (types.RVType, string, *nex.Error)
|
||||
}
|
||||
|
||||
// NewMatchmakingManager returns a new MatchmakingManager
|
||||
func NewMatchmakingManager(endpoint *nex.PRUDPEndPoint, db *sql.DB) *MatchmakingManager {
|
||||
return &MatchmakingManager{
|
||||
Endpoint: endpoint,
|
||||
Database: db,
|
||||
Mutex: &sync.RWMutex{},
|
||||
}
|
||||
}
|
187
globals/utils.go
Normal file
187
globals/utils.go
Normal file
|
@ -0,0 +1,187 @@
|
|||
package common_globals
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/constants"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
match_making_constants "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
var OutgoingCallID *nex.Counter[uint32] = nex.NewCounter[uint32](0)
|
||||
|
||||
// DeleteIndex removes a value from a slice with the given index
|
||||
func DeleteIndex(s []uint32, index int) []uint32 {
|
||||
s[index] = s[len(s)-1]
|
||||
return s[:len(s)-1]
|
||||
}
|
||||
|
||||
// RemoveDuplicates removes duplicate entries on a slice
|
||||
func RemoveDuplicates[T comparable](sliceList []T) []T {
|
||||
// * Extracted from https://stackoverflow.com/a/66751055
|
||||
allKeys := make(map[T]bool)
|
||||
list := []T{}
|
||||
for _, item := range sliceList {
|
||||
if _, value := allKeys[item]; !value {
|
||||
allKeys[item] = true
|
||||
list = append(list, item)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// CheckValidGathering checks if a Gathering is valid
|
||||
func CheckValidGathering(gathering match_making_types.Gathering) bool {
|
||||
if len(gathering.Description) > 256 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckValidMatchmakeSession checks if a MatchmakeSession is valid
|
||||
func CheckValidMatchmakeSession(matchmakeSession match_making_types.MatchmakeSession) bool {
|
||||
if !CheckValidGathering(matchmakeSession.Gathering) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(matchmakeSession.Attributes) != 6 {
|
||||
return false
|
||||
}
|
||||
|
||||
if matchmakeSession.ProgressScore > 100 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(matchmakeSession.UserPassword) > 32 {
|
||||
return false
|
||||
}
|
||||
|
||||
// * Except for UserPassword, all strings must have a length lower than 256
|
||||
if len(matchmakeSession.CodeWord) > 256 {
|
||||
return false
|
||||
}
|
||||
|
||||
// * All buffers must have a length lower than 512
|
||||
if len(matchmakeSession.ApplicationBuffer) > 512 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(matchmakeSession.SessionKey) > 512 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckValidPersistentGathering checks if a PersistentGathering is valid
|
||||
func CheckValidPersistentGathering(persistentGathering match_making_types.PersistentGathering) bool {
|
||||
if !CheckValidGathering(persistentGathering.Gathering) {
|
||||
return false
|
||||
}
|
||||
|
||||
// * Only allow normal and password-protected community types
|
||||
if uint32(persistentGathering.CommunityType) != uint32(match_making_constants.PersistentGatheringTypeOpen) && uint32(persistentGathering.CommunityType) != uint32(match_making_constants.PersistentGatheringTypePasswordLocked) {
|
||||
return false
|
||||
}
|
||||
|
||||
// * The UserPassword from a MatchmakeSession can be up to 32 characters, assuming the same here
|
||||
//
|
||||
// TODO - IS this actually the case?
|
||||
if len(persistentGathering.Password) > 32 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(persistentGathering.Attribs) != 6 {
|
||||
return false
|
||||
}
|
||||
|
||||
// * All buffers must have a length lower than 512
|
||||
if len(persistentGathering.ApplicationBuffer) > 512 {
|
||||
return false
|
||||
}
|
||||
|
||||
// * Check that the participation dates are within bounds of the current date
|
||||
currentTime := types.NewDateTime(0).Now()
|
||||
|
||||
if persistentGathering.ParticipationStartDate != 0 && persistentGathering.ParticipationStartDate > currentTime {
|
||||
return false
|
||||
}
|
||||
|
||||
if persistentGathering.ParticipationEndDate != 0 && persistentGathering.ParticipationEndDate < currentTime {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// CanJoinMatchmakeSession checks if a PID is allowed to join a matchmake session
|
||||
func CanJoinMatchmakeSession(manager *MatchmakingManager, pid types.PID, matchmakeSession match_making_types.MatchmakeSession) *nex.Error {
|
||||
// TODO - Is this the right error?
|
||||
if !matchmakeSession.OpenParticipation {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
// * Only allow friends
|
||||
// TODO - This won't work on Switch!
|
||||
if matchmakeSession.ParticipationPolicy == 98 {
|
||||
if manager.GetUserFriendPIDs == nil {
|
||||
Logger.Warning("Missing GetUserFriendPIDs!")
|
||||
return nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
friendList := manager.GetUserFriendPIDs(uint32(pid))
|
||||
if !slices.Contains(friendList, uint32(matchmakeSession.OwnerPID)) {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.NotFriend, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendNotificationEvent sends a notification event to the specified targets
|
||||
func SendNotificationEvent(endpoint *nex.PRUDPEndPoint, event notifications_types.NotificationEvent, targets []uint64) {
|
||||
server := endpoint.Server
|
||||
stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
event.WriteTo(stream)
|
||||
|
||||
rmcRequest := nex.NewRMCRequest(endpoint)
|
||||
rmcRequest.ProtocolID = notifications.ProtocolID
|
||||
rmcRequest.CallID = OutgoingCallID.Next()
|
||||
rmcRequest.MethodID = notifications.MethodProcessNotificationEvent
|
||||
rmcRequest.Parameters = stream.Bytes()
|
||||
|
||||
rmcRequestBytes := rmcRequest.Bytes()
|
||||
|
||||
for _, pid := range targets {
|
||||
target := endpoint.FindConnectionByPID(pid)
|
||||
if target == nil {
|
||||
Logger.Warning("Client not found")
|
||||
continue
|
||||
}
|
||||
|
||||
var messagePacket nex.PRUDPPacketInterface
|
||||
|
||||
if target.DefaultPRUDPVersion == 0 {
|
||||
messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil)
|
||||
} else {
|
||||
messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil)
|
||||
}
|
||||
|
||||
messagePacket.SetType(constants.DataPacket)
|
||||
messagePacket.AddFlag(constants.PacketFlagNeedsAck)
|
||||
messagePacket.AddFlag(constants.PacketFlagReliable)
|
||||
messagePacket.SetSourceVirtualPortStreamType(target.StreamType)
|
||||
messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID)
|
||||
messagePacket.SetDestinationVirtualPortStreamType(target.StreamType)
|
||||
messagePacket.SetDestinationVirtualPortStreamID(target.StreamID)
|
||||
messagePacket.SetPayload(rmcRequestBytes)
|
||||
|
||||
server.Send(messagePacket)
|
||||
}
|
||||
}
|
45
go.mod
45
go.mod
|
@ -1,19 +1,40 @@
|
|||
module github.com/PretendoNetwork/nex-protocols-common-go
|
||||
module github.com/PretendoNetwork/nex-protocols-common-go/v2
|
||||
|
||||
go 1.18
|
||||
go 1.22.1
|
||||
|
||||
toolchain go1.22.4
|
||||
|
||||
require (
|
||||
github.com/PretendoNetwork/nex-go v1.0.7
|
||||
github.com/PretendoNetwork/nex-protocols-go v1.0.4
|
||||
github.com/PretendoNetwork/plogger v1.0.1
|
||||
github.com/PretendoNetwork/nex-go/v2 v2.1.1
|
||||
github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0
|
||||
github.com/PretendoNetwork/plogger-go v1.0.4
|
||||
github.com/PretendoNetwork/pq-extended v1.0.0
|
||||
github.com/minio/minio-go/v7 v7.0.83
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/jwalton/go-supportscolor v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/superwhiskers/crunch/v3 v3.5.6 // indirect
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
|
||||
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
|
||||
github.com/dolthub/maphash v0.1.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/goccy/go-json v0.10.4 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jwalton/go-supportscolor v1.2.0 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/lxzan/gws v1.8.8 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/superwhiskers/crunch/v3 v3.5.7 // indirect
|
||||
golang.org/x/crypto v0.31.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
|
||||
golang.org/x/mod v0.22.0 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/term v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
)
|
||||
|
|
99
go.sum
99
go.sum
|
@ -1,30 +1,75 @@
|
|||
github.com/PretendoNetwork/nex-go v1.0.7 h1:iTIxBXZdVRtGT7+S56wgA0SXPsDHVaWs6lH0QZBB+Rk=
|
||||
github.com/PretendoNetwork/nex-go v1.0.7/go.mod h1:j6OToXinJyoE5QJaDo14abPTGLXPFfHl25X/XLIAR+8=
|
||||
github.com/PretendoNetwork/nex-protocols-go v1.0.4 h1:8XUbp73COqdYPYql7asuhRnRGAJuQ/Nc/OnmUQEy7NM=
|
||||
github.com/PretendoNetwork/nex-protocols-go v1.0.4/go.mod h1:+cZgKcs2hkgwGmi32Miup+my1vPn+yg3RyrrpIi6vdE=
|
||||
github.com/PretendoNetwork/plogger v1.0.1 h1:vWe/MUo139FyVciJoqmFwjtkKWEypeyM/IQYZytou4A=
|
||||
github.com/PretendoNetwork/plogger v1.0.1/go.mod h1:7DcbJTo1/p/1q2Mjkojx+/k/tSh1HLOUYwD5cO2r4mg=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
|
||||
github.com/jwalton/go-supportscolor v1.1.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/superwhiskers/crunch/v3 v3.5.6 h1:gxAMb9Ga/DerwN8jg3U1OMAEPLww3WCW465R07owRUQ=
|
||||
github.com/superwhiskers/crunch/v3 v3.5.6/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
github.com/PretendoNetwork/nex-go/v2 v2.1.1 h1:OI2W14lIw2V2kItV2c/57UGLrT6PV5CuhyU07VAAki4=
|
||||
github.com/PretendoNetwork/nex-go/v2 v2.1.1/go.mod h1:3LyJzsv3AataJW8D0binp15Q8ZH22MWTYly1VNtXi64=
|
||||
github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0 h1:abbCXgYN9icR9hmGV9GkuiOvg92+WBeVTnvtiAU06QU=
|
||||
github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0/go.mod h1:+soBHmwX6ixGxj6cphLuCvfJqxcZPuowc/5e7Qi9Bz0=
|
||||
github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc=
|
||||
github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU=
|
||||
github.com/PretendoNetwork/pq-extended v1.0.0 h1:GHZ0hLvCvmYKQPTV9I9XtTx8J1iB5Z9CEnfW2tUpsYg=
|
||||
github.com/PretendoNetwork/pq-extended v1.0.0/go.mod h1:bq6Ai+3lG4/M0iamUBt2Uzi5vL/nYy1a1Ar2ow9NDF0=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ=
|
||||
github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM=
|
||||
github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8=
|
||||
github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
|
||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
|
||||
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lxzan/gws v1.8.8 h1:st193ZG8qN8sSw8/g/UituFhs7etmKzS7jUqhijg5wM=
|
||||
github.com/lxzan/gws v1.8.8/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.0.83 h1:W4Kokksvlz3OKf3OqIlzDNKd4MERlC2oN8YptwJ0+GA=
|
||||
github.com/minio/minio-go/v7 v7.0.83/go.mod h1:57YXpvc5l3rjPdhqNrDsvVlY0qPI6UTk1bflAe+9doY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs=
|
||||
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg=
|
||||
github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA=
|
||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
|
||||
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
|
||||
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 h1:EH1Deb8WZJ0xc0WK//leUHXcX9aLE5SymusoTmMZye8=
|
||||
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
|
||||
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
github.com/PretendoNetwork/plogger v1.0.0 h1:wpS34n9eJjJgadjYKuC3VFXZ0EYbJ5/RhkBXI6h7Kmw=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
|
||||
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
52
match-making-ext/end_participation.go
Normal file
52
match-making-ext/end_participation.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package match_making_ext
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) endParticipation(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32, strMessage types.String) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(strMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
nexError := database.EndGatheringParticipation(commonProtocol.manager, uint32(idGathering), connection, string(strMessage))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
retval := types.NewBool(true)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
retval.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = match_making_ext.ProtocolID
|
||||
rmcResponse.MethodID = match_making_ext.MethodEndParticipation
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterEndParticipation != nil {
|
||||
go commonProtocol.OnAfterEndParticipation(packet, idGathering, strMessage)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
32
match-making-ext/protocol.go
Normal file
32
match-making-ext/protocol.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package match_making_ext
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext"
|
||||
)
|
||||
|
||||
type CommonProtocol struct {
|
||||
endpoint nex.EndpointInterface
|
||||
protocol match_making_ext.Interface
|
||||
manager *common_globals.MatchmakingManager
|
||||
OnAfterEndParticipation func(acket nex.PacketInterface, idGathering types.UInt32, strMessage types.String)
|
||||
}
|
||||
|
||||
// SetManager defines the matchmaking manager to be used by the common protocol
|
||||
func (commonProtocol *CommonProtocol) SetManager(manager *common_globals.MatchmakingManager) {
|
||||
commonProtocol.manager = manager
|
||||
}
|
||||
|
||||
// NewCommonProtocol returns a new CommonProtocol
|
||||
func NewCommonProtocol(protocol match_making_ext.Interface) *CommonProtocol {
|
||||
commonProtocol := &CommonProtocol{
|
||||
endpoint: protocol.Endpoint(),
|
||||
protocol: protocol,
|
||||
}
|
||||
|
||||
protocol.SetHandlerEndParticipation(commonProtocol.endParticipation)
|
||||
|
||||
return commonProtocol
|
||||
}
|
165
match-making/database/disconnect_participant.go
Normal file
165
match-making/database/disconnect_participant.go
Normal file
|
@ -0,0 +1,165 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// DisconnectParticipant disconnects a participant from all non-persistent gatherings
|
||||
func DisconnectParticipant(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection) {
|
||||
var nexError *nex.Error
|
||||
|
||||
rows, err := manager.Database.Query(`SELECT id, owner_pid, host_pid, min_participants, max_participants, participation_policy, policy_argument, flags, state, description, type, participants FROM matchmaking.gatherings WHERE $1 = ANY(participants) AND registered=true`, connection.PID())
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
gathering := match_making_types.NewGathering()
|
||||
var gatheringType string
|
||||
var participants []uint64
|
||||
|
||||
err = rows.Scan(
|
||||
&gathering.ID,
|
||||
&gathering.OwnerPID,
|
||||
&gathering.HostPID,
|
||||
&gathering.MinimumParticipants,
|
||||
&gathering.MaximumParticipants,
|
||||
&gathering.ParticipationPolicy,
|
||||
&gathering.PolicyArgument,
|
||||
&gathering.Flags,
|
||||
&gathering.State,
|
||||
&gathering.Description,
|
||||
&gatheringType,
|
||||
pqextended.Array(&participants),
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
// * If the gathering is a PersistentGathering and the gathering isn't set to leave when disconnecting, ignore and continue
|
||||
//
|
||||
// TODO - Is the match_making.GatheringFlags.PersistentGathering check correct here?
|
||||
if uint32(gathering.Flags) & match_making.GatheringFlags.PersistentGathering != 0 || (gatheringType == "PersistentGathering" && uint32(gathering.Flags) & match_making.GatheringFlags.PersistentGatheringLeaveParticipation == 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
// * Since the participant is leaving, override the participant list to avoid sending notifications to them
|
||||
participants, nexError = RemoveParticipantFromGathering(manager, uint32(gathering.ID), uint64(connection.PID()))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
nexError = tracking.LogDisconnectGathering(manager.Database, connection.PID(), uint32(gathering.ID), participants)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
// * If the gathering is a persistent gathering and allows zero users, only remove the participant from the gathering
|
||||
if uint32(gathering.Flags) & (match_making.GatheringFlags.PersistentGathering | match_making.GatheringFlags.PersistentGatheringAllowZeroUsers) != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(participants) == 0 {
|
||||
// * There are no more participants, so we only have to unregister the gathering
|
||||
// * Since the participant is disconnecting, we don't send notification events
|
||||
nexError = UnregisterGathering(manager, connection.PID(), uint32(gathering.ID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
ownerPID := uint64(gathering.OwnerPID)
|
||||
if connection.PID().Equals(gathering.OwnerPID) {
|
||||
// * This flag tells the server to change the matchmake session owner if they disconnect
|
||||
// * If the flag is not set, delete the session
|
||||
// * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags
|
||||
if uint32(gathering.Flags) & match_making.GatheringFlags.DisconnectChangeOwner == 0 {
|
||||
nexError = UnregisterGathering(manager, connection.PID(), uint32(gathering.ID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.GatheringUnregistered
|
||||
subtype := notifications.NotificationSubTypes.GatheringUnregistered.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gathering.ID
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
ownerPID, nexError = MigrateGatheringOwnership(manager, connection, gathering, participants)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// * If the host has disconnected, set the owner as the new host. We can guarantee that the ownerPID is not zero,
|
||||
// * since otherwise the gathering would have been unregistered by MigrateGatheringOwnership
|
||||
if connection.PID().Equals(gathering.HostPID) && ownerPID != 0 {
|
||||
nexError = UpdateSessionHost(manager, uint32(gathering.ID), types.NewPID(ownerPID), types.NewPID(ownerPID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
} else {
|
||||
category := notifications.NotificationCategories.HostChanged
|
||||
subtype := notifications.NotificationSubTypes.HostChanged.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gathering.ID
|
||||
|
||||
// TODO - Should the notification actually be sent to all participants?
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants))
|
||||
|
||||
nexError = tracking.LogChangeHost(manager.Database, connection.PID(), uint32(gathering.ID), gathering.HostPID, types.NewPID(ownerPID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.Participation
|
||||
subtype := notifications.NotificationSubTypes.Participation.Disconnected
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gathering.ID
|
||||
oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
|
||||
var participantEndedTargets []uint64
|
||||
|
||||
// * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
|
||||
if uint32(gathering.Flags) & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
|
||||
participantEndedTargets = common_globals.RemoveDuplicates(participants)
|
||||
} else {
|
||||
participantEndedTargets = []uint64{uint64(gathering.OwnerPID)}
|
||||
}
|
||||
|
||||
// * Only send the notification event to the owner
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantEndedTargets)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
}
|
126
match-making/database/end_gathering_participation.go
Normal file
126
match-making/database/end_gathering_participation.go
Normal file
|
@ -0,0 +1,126 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
// EndGatheringParticipation ends the participation of a connection within a gathering and performs any additional handling required
|
||||
func EndGatheringParticipation(manager *common_globals.MatchmakingManager, gatheringID uint32, connection *nex.PRUDPConnection, message string) *nex.Error {
|
||||
gathering, _, participants, _, nexError := FindGatheringByID(manager, gatheringID)
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
// TODO - Is this the right error?
|
||||
if !slices.Contains(participants, uint64(connection.PID())) {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.NotParticipatedGathering, "change_error")
|
||||
}
|
||||
|
||||
newParticipants, nexError := RemoveParticipantFromGathering(manager, gatheringID, uint64(connection.PID()))
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogLeaveGathering(manager.Database, connection.PID(), gatheringID, newParticipants)
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
// * If the gathering is a persistent gathering and allows zero users, only remove the participant from the gathering
|
||||
if uint32(gathering.Flags) & (match_making.GatheringFlags.PersistentGathering | match_making.GatheringFlags.PersistentGatheringAllowZeroUsers) != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(newParticipants) == 0 {
|
||||
// * There are no more participants, so we just unregister the gathering
|
||||
return UnregisterGathering(manager, connection.PID(), gatheringID)
|
||||
}
|
||||
|
||||
var ownerPID uint64 = uint64(gathering.OwnerPID)
|
||||
if connection.PID().Equals(gathering.OwnerPID) {
|
||||
// * This flag tells the server to change the matchmake session owner if they disconnect
|
||||
// * If the flag is not set, delete the session
|
||||
// * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags
|
||||
if uint32(gathering.Flags) & match_making.GatheringFlags.DisconnectChangeOwner == 0 {
|
||||
nexError = UnregisterGathering(manager, connection.PID(), gatheringID)
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.GatheringUnregistered
|
||||
subtype := notifications.NotificationSubTypes.GatheringUnregistered.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(newParticipants))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
ownerPID, nexError = MigrateGatheringOwnership(manager, connection, gathering, newParticipants)
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
}
|
||||
|
||||
// * If the host has disconnected, set the owner as the new host. We can guarantee that the ownerPID is not zero,
|
||||
// * since otherwise the gathering would have been unregistered by MigrateGatheringOwnership
|
||||
if connection.PID().Equals(gathering.HostPID) && ownerPID != 0 {
|
||||
nexError = UpdateSessionHost(manager, gatheringID, types.NewPID(ownerPID), types.NewPID(ownerPID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
return nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.HostChanged
|
||||
subtype := notifications.NotificationSubTypes.HostChanged.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
|
||||
// TODO - Should the notification actually be sent to all participants?
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, common_globals.RemoveDuplicates(participants))
|
||||
|
||||
nexError = tracking.LogChangeHost(manager.Database, connection.PID(), gatheringID, gathering.HostPID, types.NewPID(ownerPID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
return nexError
|
||||
}
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.Participation
|
||||
subtype := notifications.NotificationSubTypes.Participation.Ended
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
oEvent.Param2 = types.NewUInt32(uint32((connection.PID()))) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
oEvent.StrParam = types.NewString(message)
|
||||
|
||||
var participationEndedTargets []uint64
|
||||
|
||||
// * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
|
||||
if uint32(gathering.Flags) & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
|
||||
participationEndedTargets = common_globals.RemoveDuplicates(participants)
|
||||
} else {
|
||||
participationEndedTargets = []uint64{uint64(gathering.OwnerPID)}
|
||||
}
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participationEndedTargets)
|
||||
|
||||
return nil
|
||||
}
|
49
match-making/database/find_gathering_by_id.go
Normal file
49
match-making/database/find_gathering_by_id.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// FindGatheringByID finds a gathering on a database with the given ID. Returns the gathering, its type, the participant list and the started time
|
||||
func FindGatheringByID(manager *common_globals.MatchmakingManager, id uint32) (match_making_types.Gathering, string, []uint64, types.DateTime, *nex.Error) {
|
||||
row := manager.Database.QueryRow(`SELECT owner_pid, host_pid, min_participants, max_participants, participation_policy, policy_argument, flags, state, description, type, participants, started_time FROM matchmaking.gatherings WHERE id=$1 AND registered=true`, id)
|
||||
|
||||
gathering := match_making_types.NewGathering()
|
||||
var gatheringType string
|
||||
var participants []uint64
|
||||
var startedTime time.Time
|
||||
|
||||
err := row.Scan(
|
||||
&gathering.OwnerPID,
|
||||
&gathering.HostPID,
|
||||
&gathering.MinimumParticipants,
|
||||
&gathering.MaximumParticipants,
|
||||
&gathering.ParticipationPolicy,
|
||||
&gathering.PolicyArgument,
|
||||
&gathering.Flags,
|
||||
&gathering.State,
|
||||
&gathering.Description,
|
||||
&gatheringType,
|
||||
pqextended.Array(&participants),
|
||||
&startedTime,
|
||||
)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return gathering, "", nil, types.NewDateTime(0), nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, err.Error())
|
||||
} else {
|
||||
return gathering, "", nil, types.NewDateTime(0), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
gathering.ID = types.NewUInt32(id)
|
||||
startedDateTime := types.NewDateTime(0)
|
||||
|
||||
return gathering, gatheringType, participants, startedDateTime.FromTimestamp(startedTime), nil
|
||||
}
|
21
match-making/database/get_detailed_gathering_by_id.go
Normal file
21
match-making/database/get_detailed_gathering_by_id.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// GetDetailedGatheringByID returns a Gathering as an RVType by its gathering ID
|
||||
func GetDetailedGatheringByID(manager *common_globals.MatchmakingManager, sourcePID uint64, gatheringID uint32) (types.RVType, string, *nex.Error) {
|
||||
gathering, gatheringType, _, _, nexError := FindGatheringByID(manager, gatheringID)
|
||||
if nexError != nil {
|
||||
return nil, "", nexError
|
||||
}
|
||||
|
||||
if gatheringType != "Gathering" {
|
||||
return nil, "", nex.NewError(nex.ResultCodes.Core.Exception, "change_error")
|
||||
}
|
||||
|
||||
return gathering, gatheringType, nil
|
||||
}
|
121
match-making/database/join_gathering.go
Normal file
121
match-making/database/join_gathering.go
Normal file
|
@ -0,0 +1,121 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// JoinGathering joins participants from the same connection into a gathering. Returns the new number of participants
|
||||
func JoinGathering(manager *common_globals.MatchmakingManager, gatheringID uint32, connection *nex.PRUDPConnection, vacantParticipants uint16, joinMessage string) (uint32, *nex.Error) {
|
||||
// * vacantParticipants represents the total number of participants that are joining (including the main participant)
|
||||
// * Prevent underflow below if vacantParticipants is set to zero
|
||||
if vacantParticipants == 0 {
|
||||
vacantParticipants = 1
|
||||
}
|
||||
|
||||
var ownerPID uint64
|
||||
var maxParticipants uint32
|
||||
var flags uint32
|
||||
var participants []uint64
|
||||
err := manager.Database.QueryRow(`SELECT owner_pid, max_participants, flags, participants FROM matchmaking.gatherings WHERE id=$1`, gatheringID).Scan(&ownerPID, &maxParticipants, &flags, pqextended.Array(&participants))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
} else {
|
||||
return 0, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if maxParticipants != 0 {
|
||||
if uint32(len(participants)) + uint32(vacantParticipants) > maxParticipants {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionFull, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
if slices.Contains(participants, uint64(connection.PID())) {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.AlreadyParticipatedGathering, "change_error")
|
||||
}
|
||||
|
||||
var newParticipants []uint64
|
||||
|
||||
// * Additional participants are represented by duplicating the main participant PID on the array
|
||||
for range vacantParticipants {
|
||||
newParticipants = append(newParticipants, uint64(connection.PID()))
|
||||
}
|
||||
|
||||
var totalParticipants []uint64 = append(newParticipants, participants...)
|
||||
|
||||
// * We have already checked that the gathering exists above, so we don't have to check the rows affected on sql.Result
|
||||
_, err = manager.Database.Exec(`UPDATE matchmaking.gatherings SET participants=$1 WHERE id=$2`, pqextended.Array(totalParticipants), gatheringID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
} else {
|
||||
return 0, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
nexError := tracking.LogJoinGathering(manager.Database, connection.PID(), gatheringID, newParticipants, totalParticipants)
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
var participantJoinedTargets []uint64
|
||||
|
||||
// * When the VerboseParticipants or VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
|
||||
if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
|
||||
participantJoinedTargets = common_globals.RemoveDuplicates(totalParticipants)
|
||||
} else {
|
||||
// * If the new participant is the same as the owner, then we are creating a new gathering.
|
||||
// * We don't need to send notification events in that case
|
||||
if uint64(connection.PID()) == ownerPID {
|
||||
return uint32(len(totalParticipants)), nil
|
||||
}
|
||||
|
||||
participantJoinedTargets = []uint64{ownerPID}
|
||||
}
|
||||
|
||||
notificationCategory := notifications.NotificationCategories.Participation
|
||||
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
oEvent.StrParam = types.NewString(joinMessage)
|
||||
oEvent.Param3 = types.NewUInt32(uint32(len(totalParticipants)))
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantJoinedTargets)
|
||||
|
||||
// * This flag also sends a recap of all currently connected players on the gathering to the participant that is connecting
|
||||
if flags & match_making.GatheringFlags.VerboseParticipantsEx != 0 {
|
||||
// TODO - Should this actually be deduplicated?
|
||||
for _, participant := range common_globals.RemoveDuplicates(participants) {
|
||||
notificationCategory := notifications.NotificationCategories.Participation
|
||||
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
oEvent.StrParam = types.NewString(joinMessage)
|
||||
oEvent.Param3 = types.NewUInt32(uint32(len(totalParticipants)))
|
||||
|
||||
// * Send the notification to the joining participant
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{uint64(connection.PID())})
|
||||
}
|
||||
}
|
||||
|
||||
return uint32(len(totalParticipants)), nil
|
||||
}
|
140
match-making/database/join_gathering_with_participants.go
Normal file
140
match-making/database/join_gathering_with_participants.go
Normal file
|
@ -0,0 +1,140 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// JoinGatheringWithParticipants joins participants into a gathering. Returns the new number of participants
|
||||
func JoinGatheringWithParticipants(manager *common_globals.MatchmakingManager, gatheringID uint32, connection *nex.PRUDPConnection, additionalParticipants []types.PID, joinMessage string, joinMatchmakeSessionBehavior constants.JoinMatchmakeSessionBehavior) (uint32, *nex.Error) {
|
||||
var ownerPID uint64
|
||||
var maxParticipants uint32
|
||||
var flags uint32
|
||||
var oldParticipants []uint64
|
||||
err := manager.Database.QueryRow(`SELECT owner_pid, max_participants, flags, participants FROM matchmaking.gatherings WHERE id=$1`, gatheringID).Scan(&ownerPID, &maxParticipants, &flags, pqextended.Array(&oldParticipants))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
} else {
|
||||
return 0, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if uint32(len(oldParticipants) + 1 + len(additionalParticipants)) > maxParticipants {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.SessionFull, "change_error")
|
||||
}
|
||||
|
||||
var newParticipants []uint64
|
||||
|
||||
// * If joinMatchmakeSessionBehavior is set to 1, we check if the caller is already joined into the session
|
||||
if joinMatchmakeSessionBehavior == constants.JoinMatchmakeSessionBehaviorImAlreadyJoined {
|
||||
if !slices.Contains(oldParticipants, uint64(connection.PID())) {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.NotParticipatedGathering, "change_error")
|
||||
}
|
||||
} else {
|
||||
if slices.Contains(oldParticipants, uint64(connection.PID())) {
|
||||
return 0, nex.NewError(nex.ResultCodes.RendezVous.AlreadyParticipatedGathering, "change_error")
|
||||
}
|
||||
|
||||
// * Only include the caller as a new participant when they aren't joined
|
||||
newParticipants = []uint64{uint64(connection.PID())}
|
||||
}
|
||||
|
||||
for _, participant := range additionalParticipants {
|
||||
newParticipants = append(newParticipants, uint64(participant))
|
||||
}
|
||||
|
||||
participants := append(oldParticipants, newParticipants...)
|
||||
|
||||
// * We have already checked that the gathering exists above, so we don't have to check the rows affected on sql.Result
|
||||
_, err = manager.Database.Exec(`UPDATE matchmaking.gatherings SET participants=$1 WHERE id=$2`, pqextended.Array(participants), gatheringID)
|
||||
if err != nil {
|
||||
return 0, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
// NOTE - This will log even if no new participants are added
|
||||
nexError := tracking.LogJoinGathering(manager.Database, connection.PID(), gatheringID, newParticipants, participants)
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
var participantJoinedTargets []uint64
|
||||
|
||||
// * When the VerboseParticipants or the VerboseParticipantsEx flags are set, all participant notification events are sent to everyone
|
||||
if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 {
|
||||
participantJoinedTargets = common_globals.RemoveDuplicates(participants)
|
||||
} else {
|
||||
participantJoinedTargets = []uint64{ownerPID}
|
||||
}
|
||||
|
||||
// * Send the switch SwitchGathering to the new participants first
|
||||
for _, participant := range common_globals.RemoveDuplicates(newParticipants) {
|
||||
// * Don't send the SwitchGathering notification to the participant that requested the join
|
||||
if uint64(connection.PID()) == participant {
|
||||
continue
|
||||
}
|
||||
|
||||
notificationCategory := notifications.NotificationCategories.SwitchGathering
|
||||
notificationSubtype := notifications.NotificationSubTypes.SwitchGathering.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
|
||||
// * Send the notification to the participant
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{participant})
|
||||
}
|
||||
|
||||
for _, participant := range newParticipants {
|
||||
// * If the new participant is the same as the owner, then we are creating a new gathering.
|
||||
// * We don't need to send the new participant notification event in that case
|
||||
if flags & (match_making.GatheringFlags.VerboseParticipants | match_making.GatheringFlags.VerboseParticipantsEx) != 0 || uint64(connection.PID()) != ownerPID {
|
||||
notificationCategory := notifications.NotificationCategories.Participation
|
||||
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
oEvent.Param2 = types.NewUInt32(uint32(participant)) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
oEvent.StrParam = types.NewString(joinMessage)
|
||||
oEvent.Param3 = types.NewUInt32(uint32(len(participants)))
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, participantJoinedTargets)
|
||||
}
|
||||
|
||||
// * This flag also sends a recap of all currently connected players on the gathering to the participant that is connecting
|
||||
if flags & match_making.GatheringFlags.VerboseParticipantsEx != 0 {
|
||||
// TODO - Should this actually be deduplicated?
|
||||
for _, oldParticipant := range common_globals.RemoveDuplicates(oldParticipants) {
|
||||
notificationCategory := notifications.NotificationCategories.Participation
|
||||
notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(notificationCategory, notificationSubtype))
|
||||
oEvent.Param1 = types.NewUInt32(gatheringID)
|
||||
oEvent.Param2 = types.NewUInt32(uint32(oldParticipant)) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
oEvent.StrParam = types.NewString(joinMessage)
|
||||
oEvent.Param3 = types.NewUInt32(uint32(len(participants)))
|
||||
|
||||
// * Send the notification to the joining participant
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, []uint64{participant})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uint32(len(participants)), nil
|
||||
}
|
75
match-making/database/migrate_gathering_ownership.go
Normal file
75
match-making/database/migrate_gathering_ownership.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
// MigrateGatheringOwnership switches the owner of the gathering with a different one
|
||||
func MigrateGatheringOwnership(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, gathering match_making_types.Gathering, participants []uint64) (uint64, *nex.Error) {
|
||||
var nexError *nex.Error
|
||||
var uniqueParticipants []uint64 = common_globals.RemoveDuplicates(participants)
|
||||
var newOwner uint64
|
||||
for _, participant := range uniqueParticipants {
|
||||
if participant != uint64(gathering.OwnerPID) {
|
||||
newOwner = participant
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// * We couldn't find a new owner, so we unregister the gathering
|
||||
if newOwner == 0 {
|
||||
nexError = UnregisterGathering(manager, connection.PID(), uint32(gathering.ID))
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.GatheringUnregistered
|
||||
subtype := notifications.NotificationSubTypes.GatheringUnregistered.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gathering.ID
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, uniqueParticipants)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
oldOwner := gathering.OwnerPID.Copy().(types.PID)
|
||||
|
||||
// * Set the new owner
|
||||
gathering.OwnerPID = types.NewPID(newOwner)
|
||||
|
||||
nexError = UpdateSessionHost(manager, uint32(gathering.ID), gathering.OwnerPID, gathering.HostPID)
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeOwner(manager.Database, connection.PID(), uint32(gathering.ID), oldOwner, gathering.OwnerPID)
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.OwnershipChanged
|
||||
subtype := notifications.NotificationSubTypes.OwnershipChanged.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gathering.ID
|
||||
oEvent.Param2 = types.NewUInt32(uint32(newOwner)) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
|
||||
// TODO - StrParam doesn't have this value on some servers
|
||||
// * https://github.com/kinnay/NintendoClients/issues/101
|
||||
// * unixTime := time.Now()
|
||||
// * oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10)
|
||||
|
||||
common_globals.SendNotificationEvent(connection.Endpoint().(*nex.PRUDPEndPoint), oEvent, uniqueParticipants)
|
||||
return newOwner, nil
|
||||
}
|
68
match-making/database/register_gathering.go
Normal file
68
match-making/database/register_gathering.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
)
|
||||
|
||||
// RegisterGathering registers a new gathering on the database. No participants are added
|
||||
func RegisterGathering(manager *common_globals.MatchmakingManager, ownerPID types.PID, hostPID types.PID, gathering *match_making_types.Gathering, gatheringType string) (types.DateTime, *nex.Error) {
|
||||
startedTime := types.NewDateTime(0).Now()
|
||||
var gatheringID uint32
|
||||
|
||||
err := manager.Database.QueryRow(`INSERT INTO matchmaking.gatherings (
|
||||
owner_pid,
|
||||
host_pid,
|
||||
min_participants,
|
||||
max_participants,
|
||||
participation_policy,
|
||||
policy_argument,
|
||||
flags,
|
||||
state,
|
||||
description,
|
||||
type,
|
||||
started_time
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8,
|
||||
$9,
|
||||
$10,
|
||||
$11
|
||||
) RETURNING id`,
|
||||
ownerPID,
|
||||
hostPID,
|
||||
gathering.MinimumParticipants,
|
||||
gathering.MaximumParticipants,
|
||||
gathering.ParticipationPolicy,
|
||||
gathering.PolicyArgument,
|
||||
gathering.Flags,
|
||||
gathering.State,
|
||||
gathering.Description,
|
||||
gatheringType,
|
||||
startedTime.Standard(),
|
||||
).Scan(&gatheringID)
|
||||
if err != nil {
|
||||
return types.NewDateTime(0), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
gathering.ID = types.NewUInt32(gatheringID)
|
||||
|
||||
nexError := tracking.LogRegisterGathering(manager.Database, ownerPID, uint32(gathering.ID))
|
||||
if nexError != nil {
|
||||
return types.NewDateTime(0), nexError
|
||||
}
|
||||
|
||||
gathering.OwnerPID = ownerPID.Copy().(types.PID)
|
||||
gathering.HostPID = hostPID.Copy().(types.PID)
|
||||
|
||||
return startedTime, nil
|
||||
}
|
24
match-making/database/remove_participant_from_gathering.go
Normal file
24
match-making/database/remove_participant_from_gathering.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// RemoveParticipantFromGathering removes a participant from a gathering. Returns the new list of participants
|
||||
func RemoveParticipantFromGathering(manager *common_globals.MatchmakingManager, gatheringID uint32, participant uint64) ([]uint64, *nex.Error) {
|
||||
var newParticipants []uint64
|
||||
err := manager.Database.QueryRow(`UPDATE matchmaking.gatherings SET participants=array_remove(participants, $1) WHERE id=$2 RETURNING participants`, participant, gatheringID).Scan(pqextended.Array(&newParticipants))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
} else {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return newParticipants, nil
|
||||
}
|
32
match-making/database/unregister_gathering.go
Normal file
32
match-making/database/unregister_gathering.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
)
|
||||
|
||||
// UnregisterGathering unregisters a given gathering on a database
|
||||
func UnregisterGathering(manager *common_globals.MatchmakingManager, sourcePID types.PID, id uint32) *nex.Error {
|
||||
result, err := manager.Database.Exec(`UPDATE matchmaking.gatherings SET registered=false WHERE id=$1`, id)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
}
|
||||
|
||||
nexError := tracking.LogUnregisterGathering(manager.Database, sourcePID, id)
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
26
match-making/database/update_session_host.go
Normal file
26
match-making/database/update_session_host.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdateSessionHost updates the owner and host PID of the session
|
||||
func UpdateSessionHost(manager *common_globals.MatchmakingManager, gatheringID uint32, ownerPID types.PID, hostPID types.PID) *nex.Error {
|
||||
result, err := manager.Database.Exec(`UPDATE matchmaking.gatherings SET owner_pid=$1, host_pid=$2 WHERE id=$3`, ownerPID, hostPID, gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
51
match-making/find_by_single_id.go
Normal file
51
match-making/find_by_single_id.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.PacketInterface, callID uint32, id types.UInt32) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
gathering, _, nexError := commonProtocol.manager.GetDetailedGatheringByID(commonProtocol.manager, uint64(connection.PID()), uint32(id))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
bResult := types.NewBool(true)
|
||||
pGathering := match_making_types.NewGatheringHolder()
|
||||
pGathering.Object = gathering.Copy().(match_making_types.GatheringInterface)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
bResult.WriteTo(rmcResponseStream)
|
||||
pGathering.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = match_making.ProtocolID
|
||||
rmcResponse.MethodID = match_making.MethodFindBySingleID
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterFindBySingleID != nil {
|
||||
go commonProtocol.OnAfterFindBySingleID(packet, id)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
61
match-making/get_session_urls.go
Normal file
61
match-making/get_session_urls.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getSessionURLs(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(gid))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if !slices.Contains(participants, uint64(connection.PID())) {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
host := endpoint.FindConnectionByPID(uint64(gathering.HostPID))
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
// * If no host was found, return an empty list of station URLs
|
||||
if host == nil {
|
||||
common_globals.Logger.Error("Host client not found")
|
||||
stationURLs := types.NewList[types.StationURL]()
|
||||
stationURLs.WriteTo(rmcResponseStream)
|
||||
} else {
|
||||
host.StationURLs.WriteTo(rmcResponseStream)
|
||||
}
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = match_making.ProtocolID
|
||||
rmcResponse.MethodID = match_making.MethodGetSessionURLs
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetSessionURLs != nil {
|
||||
go commonProtocol.OnAfterGetSessionURLs(packet, gid)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
174
match-making/protocol.go
Normal file
174
match-making/protocol.go
Normal file
|
@ -0,0 +1,174 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
_ "github.com/PretendoNetwork/nex-protocols-go/v2"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
)
|
||||
|
||||
type CommonProtocol struct {
|
||||
endpoint *nex.PRUDPEndPoint
|
||||
protocol match_making.Interface
|
||||
manager *common_globals.MatchmakingManager
|
||||
OnAfterUnregisterGathering func(packet nex.PacketInterface, idGathering types.UInt32)
|
||||
OnAfterFindBySingleID func(packet nex.PacketInterface, id types.UInt32)
|
||||
OnAfterUpdateSessionURL func(packet nex.PacketInterface, idGathering types.UInt32, strURL types.String)
|
||||
OnAfterUpdateSessionHostV1 func(packet nex.PacketInterface, gid types.UInt32)
|
||||
OnAfterGetSessionURLs func(packet nex.PacketInterface, gid types.UInt32)
|
||||
OnAfterUpdateSessionHost func(packet nex.PacketInterface, gid types.UInt32, isMigrateOwner types.Bool)
|
||||
}
|
||||
|
||||
// SetManager defines the matchmaking manager to be used by the common protocol
|
||||
func (commonProtocol *CommonProtocol) SetManager(manager *common_globals.MatchmakingManager) {
|
||||
var err error
|
||||
|
||||
commonProtocol.manager = manager
|
||||
|
||||
manager.GetDetailedGatheringByID = database.GetDetailedGatheringByID
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE SCHEMA IF NOT EXISTS matchmaking`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS matchmaking.gatherings (
|
||||
id bigserial PRIMARY KEY,
|
||||
owner_pid numeric(10),
|
||||
host_pid numeric(10),
|
||||
min_participants integer,
|
||||
max_participants integer,
|
||||
participation_policy bigint,
|
||||
policy_argument bigint,
|
||||
flags bigint,
|
||||
state bigint,
|
||||
description text,
|
||||
registered boolean NOT NULL DEFAULT true,
|
||||
type text NOT NULL DEFAULT '',
|
||||
started_time timestamp,
|
||||
participants numeric(10)[] NOT NULL DEFAULT array[]::numeric(10)[]
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE SCHEMA IF NOT EXISTS tracking`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.register_gathering (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.join_gathering (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint,
|
||||
new_participants numeric(10)[] NOT NULL DEFAULT array[]::numeric(10)[],
|
||||
total_participants numeric(10)[] NOT NULL DEFAULT array[]::numeric(10)[]
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.leave_gathering (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint,
|
||||
total_participants numeric(10)[] NOT NULL DEFAULT array[]::numeric(10)[]
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.disconnect_gathering (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint,
|
||||
total_participants numeric(10)[] NOT NULL DEFAULT array[]::numeric(10)[]
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.unregister_gathering (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.change_host (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint,
|
||||
old_host_pid numeric(10),
|
||||
new_host_pid numeric(10)
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err = manager.Database.Exec(`CREATE TABLE IF NOT EXISTS tracking.change_owner (
|
||||
id bigserial PRIMARY KEY,
|
||||
date timestamp,
|
||||
source_pid numeric(10),
|
||||
gathering_id bigint,
|
||||
old_owner_pid numeric(10),
|
||||
new_owner_pid numeric(10)
|
||||
)`)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// NewCommonProtocol returns a new CommonProtocol
|
||||
func NewCommonProtocol(protocol match_making.Interface) *CommonProtocol {
|
||||
endpoint := protocol.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol := &CommonProtocol{
|
||||
endpoint: endpoint,
|
||||
protocol: protocol,
|
||||
}
|
||||
|
||||
protocol.SetHandlerUnregisterGathering(commonProtocol.unregisterGathering)
|
||||
protocol.SetHandlerFindBySingleID(commonProtocol.findBySingleID)
|
||||
protocol.SetHandlerUpdateSessionURL(commonProtocol.updateSessionURL)
|
||||
protocol.SetHandlerUpdateSessionHostV1(commonProtocol.updateSessionHostV1)
|
||||
protocol.SetHandlerGetSessionURLs(commonProtocol.getSessionURLs)
|
||||
protocol.SetHandlerUpdateSessionHost(commonProtocol.updateSessionHost)
|
||||
|
||||
endpoint.OnConnectionEnded(func(connection *nex.PRUDPConnection) {
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
database.DisconnectParticipant(commonProtocol.manager, connection)
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
})
|
||||
|
||||
return commonProtocol
|
||||
}
|
33
match-making/tracking/log_change_host.go
Normal file
33
match-making/tracking/log_change_host.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
)
|
||||
|
||||
// LogChangeHost logs a host change event on the given database
|
||||
func LogChangeHost(db *sql.DB, sourcePID types.PID, gatheringID uint32, oldHostPID types.PID, newHostPID types.PID) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.change_host (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id,
|
||||
old_host_pid,
|
||||
new_host_pid
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
)`, eventTime, sourcePID, gatheringID, oldHostPID, newHostPID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
33
match-making/tracking/log_change_owner.go
Normal file
33
match-making/tracking/log_change_owner.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
)
|
||||
|
||||
// LogChangeOwner logs an owner change event on the given database
|
||||
func LogChangeOwner(db *sql.DB, sourcePID types.PID, gatheringID uint32, oldOwnerPID types.PID, newOwnerPID types.PID) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.change_owner (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id,
|
||||
old_owner_pid,
|
||||
new_owner_pid
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
)`, eventTime, sourcePID, gatheringID, oldOwnerPID, newOwnerPID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
32
match-making/tracking/log_disconnect_gathering.go
Normal file
32
match-making/tracking/log_disconnect_gathering.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// LogDisconnectGathering logs a gathering disconnect event on the given database
|
||||
func LogDisconnectGathering(db *sql.DB, pid types.PID, gatheringID uint32, totalParticipants []uint64) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.disconnect_gathering (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id,
|
||||
total_participants
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4
|
||||
)`, eventTime, pid, gatheringID, pqextended.Array(totalParticipants))
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
34
match-making/tracking/log_join_gathering.go
Normal file
34
match-making/tracking/log_join_gathering.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// LogJoinGathering logs a gathering join event on the given database
|
||||
func LogJoinGathering(db *sql.DB, sourcePID types.PID, gatheringID uint32, newParticipants []uint64, totalParticipants []uint64) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.join_gathering (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id,
|
||||
new_participants,
|
||||
total_participants
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
)`, eventTime, sourcePID, gatheringID, pqextended.Array(newParticipants), pqextended.Array(totalParticipants))
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
32
match-making/tracking/log_leave_gathering.go
Normal file
32
match-making/tracking/log_leave_gathering.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// LogLeaveGathering logs a gathering leave event on the given database
|
||||
func LogLeaveGathering(db *sql.DB, pid types.PID, gatheringID uint32, totalParticipants []uint64) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.leave_gathering (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id,
|
||||
total_participants
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4
|
||||
)`, eventTime, pid, gatheringID, pqextended.Array(totalParticipants))
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
29
match-making/tracking/log_register_gathering.go
Normal file
29
match-making/tracking/log_register_gathering.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
)
|
||||
|
||||
// LogRegisterGathering logs a gathering registration event on the given database
|
||||
func LogRegisterGathering(db *sql.DB, sourcePID types.PID, gatheringID uint32) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.register_gathering (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
)`, eventTime, sourcePID, gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
29
match-making/tracking/log_unregister_gathering.go
Normal file
29
match-making/tracking/log_unregister_gathering.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package tracking
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
)
|
||||
|
||||
// LogUnregisterGathering logs a gathering registration event on the given database
|
||||
func LogUnregisterGathering(db *sql.DB, sourcePID types.PID, gatheringID uint32) *nex.Error {
|
||||
eventTime := time.Now().UTC()
|
||||
|
||||
_, err := db.Exec(`INSERT INTO tracking.unregister_gathering (
|
||||
date,
|
||||
source_pid,
|
||||
gathering_id
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
)`, eventTime, sourcePID, gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
70
match-making/unregister_gathering.go
Normal file
70
match-making/unregister_gathering.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) unregisterGathering(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(idGathering))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if !gathering.OwnerPID.Equals(connection.PID()) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
nexError = database.UnregisterGathering(commonProtocol.manager, connection.PID(), uint32(idGathering))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.GatheringUnregistered
|
||||
subtype := notifications.NotificationSubTypes.GatheringUnregistered.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID().Copy().(types.PID)
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = idGathering
|
||||
|
||||
common_globals.SendNotificationEvent(endpoint, oEvent, common_globals.RemoveDuplicates(participants))
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
retval := types.NewBool(true)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
retval.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = match_making.ProtocolID
|
||||
rmcResponse.MethodID = match_making.MethodUnregisterGathering
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterUnregisterGathering != nil {
|
||||
go commonProtocol.OnAfterUnregisterGathering(packet, idGathering)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
102
match-making/update_session_host.go
Normal file
102
match-making/update_session_host.go
Normal file
|
@ -0,0 +1,102 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) updateSessionHost(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, isMigrateOwner types.Bool) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(gid))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if !slices.Contains(participants, uint64(connection.PID())) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
if !isMigrateOwner {
|
||||
nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), gathering.OwnerPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
} else {
|
||||
if uint32(gathering.Flags) & match_making.GatheringFlags.ParticipantsChangeOwner == 0 {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidOperation, "change_error")
|
||||
}
|
||||
|
||||
nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), connection.PID(), connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeOwner(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.OwnerPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.OwnershipChanged
|
||||
subtype := notifications.NotificationSubTypes.OwnershipChanged.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gid
|
||||
oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
|
||||
// TODO - StrParam doesn't have this value on some servers
|
||||
// * https://github.com/kinnay/NintendoClients/issues/101
|
||||
// * unixTime := time.Now()
|
||||
// * oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10)
|
||||
|
||||
common_globals.SendNotificationEvent(endpoint, oEvent, common_globals.RemoveDuplicates(participants))
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = match_making.ProtocolID
|
||||
rmcResponse.MethodID = match_making.MethodUpdateSessionHost
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterUpdateSessionHost != nil {
|
||||
go commonProtocol.OnAfterUpdateSessionHost(packet, gid, isMigrateOwner)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
98
match-making/update_session_host_v1.go
Normal file
98
match-making/update_session_host_v1.go
Normal file
|
@ -0,0 +1,98 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(gid))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if !slices.Contains(participants, uint64(connection.PID())) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
if uint32(gathering.Flags) & match_making.GatheringFlags.ParticipantsChangeOwner == 0 {
|
||||
nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), gathering.OwnerPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
} else {
|
||||
nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(gid), connection.PID(), connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.HostPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeOwner(commonProtocol.manager.Database, connection.PID(), uint32(gid), gathering.OwnerPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
category := notifications.NotificationCategories.OwnershipChanged
|
||||
subtype := notifications.NotificationSubTypes.OwnershipChanged.None
|
||||
|
||||
oEvent := notifications_types.NewNotificationEvent()
|
||||
oEvent.PIDSource = connection.PID()
|
||||
oEvent.Type = types.NewUInt32(notifications.BuildNotificationType(category, subtype))
|
||||
oEvent.Param1 = gid
|
||||
oEvent.Param2 = types.NewUInt32(uint32(connection.PID())) // TODO - This assumes a legacy client. Will not work on the Switch
|
||||
|
||||
// TODO - StrParam doesn't have this value on some servers
|
||||
// * https://github.com/kinnay/NintendoClients/issues/101
|
||||
// * unixTime := time.Now()
|
||||
// * oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10)
|
||||
|
||||
common_globals.SendNotificationEvent(endpoint, oEvent, common_globals.RemoveDuplicates(participants))
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = match_making.ProtocolID
|
||||
rmcResponse.MethodID = match_making.MethodUpdateSessionHostV1
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterUpdateSessionHostV1 != nil {
|
||||
go commonProtocol.OnAfterUpdateSessionHostV1(packet, gid)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
70
match-making/update_session_url.go
Normal file
70
match-making/update_session_url.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package matchmaking
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/tracking"
|
||||
match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32, strURL types.String) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
gathering, _, participants, _, nexError := database.FindGatheringByID(commonProtocol.manager, uint32(idGathering))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if !slices.Contains(participants, uint64(connection.PID())) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
// TODO - Mario Kart 7 seems to set an empty strURL. What does that do if it's actually set?
|
||||
|
||||
// * Only update the host
|
||||
nexError = database.UpdateSessionHost(commonProtocol.manager, uint32(idGathering), gathering.OwnerPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
nexError = tracking.LogChangeHost(commonProtocol.manager.Database, connection.PID(), uint32(idGathering), gathering.HostPID, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
retval := types.NewBool(true)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
retval.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = match_making.ProtocolID
|
||||
rmcResponse.MethodID = match_making.MethodGetSessionURLs
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterUpdateSessionURL != nil {
|
||||
go commonProtocol.OnAfterUpdateSessionURL(packet, idGathering, strURL)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
99
matchmake-extension/auto_matchmake_postpone.go
Normal file
99
matchmake-extension/auto_matchmake_postpone.go
Normal file
|
@ -0,0 +1,99 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
database "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet nex.PacketInterface, callID uint32, anyGathering match_making_types.GatheringHolder, message types.String) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.CleanupSearchMatchmakeSession == nil {
|
||||
common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmake_Postpone missing CleanupSearchMatchmakeSession!")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(message) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
// * A client may disconnect from a session without leaving reliably,
|
||||
// * so let's make sure the client is removed from the session
|
||||
database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection)
|
||||
|
||||
var matchmakeSession match_making_types.MatchmakeSession
|
||||
|
||||
if anyGathering.Object.ObjectID().Equals(types.NewString("MatchmakeSession")) {
|
||||
matchmakeSession = anyGathering.Object.(match_making_types.MatchmakeSession)
|
||||
} else {
|
||||
common_globals.Logger.Critical("Non-MatchmakeSession DataType?!")
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if !common_globals.CheckValidMatchmakeSession(matchmakeSession) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
searchMatchmakeSession := matchmakeSession.Copy().(match_making_types.MatchmakeSession)
|
||||
commonProtocol.CleanupSearchMatchmakeSession(&searchMatchmakeSession)
|
||||
resultSession, nexError := database.FindMatchmakeSession(commonProtocol.manager, connection, searchMatchmakeSession)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
if resultSession == nil {
|
||||
newMatchmakeSession := searchMatchmakeSession.Copy().(match_making_types.MatchmakeSession)
|
||||
resultSession = &newMatchmakeSession
|
||||
nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, resultSession)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
}
|
||||
|
||||
participants, nexError := database.JoinMatchmakeSession(commonProtocol.manager, *resultSession, connection, 1, string(message))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
resultSession.ParticipationCount = types.NewUInt32(participants)
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
matchmakeDataHolder := match_making_types.NewGatheringHolder()
|
||||
matchmakeDataHolder.Object = resultSession.Copy().(match_making_types.GatheringInterface)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
matchmakeDataHolder.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodAutoMatchmakePostpone
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterAutoMatchmakePostpone != nil {
|
||||
go commonProtocol.OnAfterAutoMatchmakePostpone(packet, anyGathering, message)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
105
matchmake-extension/auto_matchmake_with_param_postpone.go
Normal file
105
matchmake-extension/auto_matchmake_with_param_postpone.go
Normal file
|
@ -0,0 +1,105 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.CleanupMatchmakeSessionSearchCriterias == nil {
|
||||
common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmakeWithParam_Postpone missing CleanupMatchmakeSessionSearchCriterias!")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if !common_globals.CheckValidMatchmakeSession(autoMatchmakeParam.SourceMatchmakeSession) {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(autoMatchmakeParam.JoinMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
if autoMatchmakeParam.GIDForParticipationCheck != 0 {
|
||||
// * Check that all new participants are participating in the specified gathering ID
|
||||
nexError := database.CheckGatheringForParticipation(commonProtocol.manager, uint32(autoMatchmakeParam.GIDForParticipationCheck), append(autoMatchmakeParam.AdditionalParticipants, connection.PID()))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
}
|
||||
|
||||
// * A client may disconnect from a session without leaving reliably,
|
||||
// * so let's make sure the client is removed from the session
|
||||
database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection)
|
||||
|
||||
commonProtocol.CleanupMatchmakeSessionSearchCriterias(autoMatchmakeParam.LstSearchCriteria)
|
||||
|
||||
resultRange := types.NewResultRange()
|
||||
resultRange.Length = 1
|
||||
resultSessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, autoMatchmakeParam.LstSearchCriteria, resultRange, &autoMatchmakeParam.SourceMatchmakeSession)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
var resultSession match_making_types.MatchmakeSession
|
||||
if len(resultSessions) == 0 {
|
||||
resultSession = autoMatchmakeParam.SourceMatchmakeSession.Copy().(match_making_types.MatchmakeSession)
|
||||
nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, &resultSession)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
} else {
|
||||
resultSession = resultSessions[0]
|
||||
|
||||
// TODO - What should really happen here?
|
||||
if resultSession.UserPasswordEnabled || resultSession.SystemPasswordEnabled {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
participants, nexError := database.JoinMatchmakeSessionWithParticipants(commonProtocol.manager, resultSession, connection, autoMatchmakeParam.AdditionalParticipants, string(autoMatchmakeParam.JoinMessage), constants.JoinMatchmakeSessionBehaviorJoinMyself)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
resultSession.ParticipationCount = types.NewUInt32(participants)
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
resultSession.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodAutoMatchmakeWithParamPostpone
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterAutoMatchmakeWithParamPostpone != nil {
|
||||
go commonProtocol.OnAfterAutoMatchmakeWithParamPostpone(packet, autoMatchmakeParam)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria types.List[match_making_types.MatchmakeSessionSearchCriteria], anyGathering match_making_types.GatheringHolder, strMessage types.String) (*nex.RMCMessage, *nex.Error) {
|
||||
if commonProtocol.CleanupMatchmakeSessionSearchCriterias == nil {
|
||||
common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmakeWithSearchCriteria_Postpone missing CleanupMatchmakeSessionSearchCriterias!")
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(strMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(lstSearchCriteria) > 2 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
// * A client may disconnect from a session without leaving reliably,
|
||||
// * so let's make sure the client is removed from the session
|
||||
database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection)
|
||||
|
||||
var matchmakeSession match_making_types.MatchmakeSession
|
||||
|
||||
if anyGathering.Object.GatheringObjectID().Equals(types.NewString("MatchmakeSession")) {
|
||||
matchmakeSession = anyGathering.Object.(match_making_types.MatchmakeSession)
|
||||
} else {
|
||||
common_globals.Logger.Critical("Non-MatchmakeSession DataType?!")
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if !common_globals.CheckValidMatchmakeSession(matchmakeSession) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.CleanupMatchmakeSessionSearchCriterias(lstSearchCriteria)
|
||||
|
||||
resultRange := types.NewResultRange()
|
||||
resultRange.Length = 1
|
||||
resultSessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, lstSearchCriteria, resultRange, &matchmakeSession)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
var resultSession match_making_types.MatchmakeSession
|
||||
if len(resultSessions) == 0 {
|
||||
resultSession = matchmakeSession.Copy().(match_making_types.MatchmakeSession)
|
||||
nexError = database.CreateMatchmakeSession(commonProtocol.manager, connection, &resultSession)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
} else {
|
||||
resultSession = resultSessions[0]
|
||||
|
||||
// TODO - What should really happen here?
|
||||
if resultSession.UserPasswordEnabled || resultSession.SystemPasswordEnabled {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
var vacantParticipants uint16 = 1
|
||||
if len(lstSearchCriteria) > 0 {
|
||||
vacantParticipants = uint16(lstSearchCriteria[0].VacantParticipants)
|
||||
}
|
||||
|
||||
participants, nexError := database.JoinMatchmakeSession(commonProtocol.manager, resultSession, connection, vacantParticipants, string(strMessage))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
resultSession.ParticipationCount = types.NewUInt32(participants)
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
matchmakeDataHolder := match_making_types.NewGatheringHolder()
|
||||
matchmakeDataHolder.Object = resultSession.Copy().(match_making_types.GatheringInterface)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
matchmakeDataHolder.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodAutoMatchmakeWithSearchCriteriaPostpone
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterAutoMatchmakeWithSearchCriteriaPostpone != nil {
|
||||
go commonProtocol.OnAfterAutoMatchmakeWithSearchCriteriaPostpone(packet, lstSearchCriteria, anyGathering, strMessage)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
69
matchmake-extension/browse_matchmake_session.go
Normal file
69
matchmake-extension/browse_matchmake_session.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, searchCriteria match_making_types.MatchmakeSessionSearchCriteria, resultRange types.ResultRange) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
searchCriterias := []match_making_types.MatchmakeSessionSearchCriteria{searchCriteria}
|
||||
|
||||
lstSearchCriteria := types.NewList[match_making_types.MatchmakeSessionSearchCriteria]()
|
||||
lstSearchCriteria = searchCriterias
|
||||
|
||||
if commonProtocol.CleanupMatchmakeSessionSearchCriterias != nil {
|
||||
commonProtocol.CleanupMatchmakeSessionSearchCriterias(lstSearchCriteria)
|
||||
}
|
||||
|
||||
sessions, nexError := database.FindMatchmakeSessionBySearchCriteria(commonProtocol.manager, connection, searchCriterias, resultRange, nil)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
lstGathering := types.NewList[match_making_types.GatheringHolder]()
|
||||
|
||||
for _, session := range sessions {
|
||||
// * Scrap session key and user password
|
||||
session.SessionKey = make([]byte, 0)
|
||||
session.UserPassword = ""
|
||||
|
||||
matchmakeSessionDataHolder := match_making_types.NewGatheringHolder()
|
||||
matchmakeSessionDataHolder.Object = session.Copy().(match_making_types.GatheringInterface)
|
||||
|
||||
lstGathering = append(lstGathering, matchmakeSessionDataHolder)
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
lstGathering.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodBrowseMatchmakeSession
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterBrowseMatchmakeSession != nil {
|
||||
go commonProtocol.OnAfterBrowseMatchmakeSession(packet, searchCriteria, resultRange)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
51
matchmake-extension/close_participation.go
Normal file
51
matchmake-extension/close_participation.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) closeParticipation(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
session, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
if !session.Gathering.OwnerPID.Equals(connection.PID()) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
nexError = database.UpdateParticipation(commonProtocol.manager, uint32(gid), false)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, nil)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodCloseParticipation
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterCloseParticipation != nil {
|
||||
go commonProtocol.OnAfterCloseParticipation(packet, gid)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
69
matchmake-extension/create_community.go
Normal file
69
matchmake-extension/create_community.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) createCommunity(err error, packet nex.PacketInterface, callID uint32, community match_making_types.PersistentGathering, strMessage types.String) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if !common_globals.CheckValidPersistentGathering(community) {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
createdPersistentGatherings, nexError := database.GetCreatedPersistentGatherings(commonProtocol.manager, connection.PID())
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
if createdPersistentGatherings >= commonProtocol.PersistentGatheringCreationMax {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PersistentGatheringCreationMax, "change_error")
|
||||
}
|
||||
|
||||
nexError = database.CreatePersistentGathering(commonProtocol.manager, connection, &community)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
_, nexError = match_making_database.JoinGathering(commonProtocol.manager, uint32(community.ID), connection, 1, string(strMessage))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
community.ID.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodCreateCommunity
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterCreateCommunity != nil {
|
||||
go commonProtocol.OnAfterCreateCommunity(packet, community, strMessage)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
85
matchmake-extension/create_matchmake_session.go
Normal file
85
matchmake-extension/create_matchmake_session.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, anyGathering match_making_types.GatheringHolder, message types.String, participationCount types.UInt16) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(message) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
server := endpoint.Server
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
// * A client may disconnect from a session without leaving reliably,
|
||||
// * so let's make sure the client is removed from the session
|
||||
database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection)
|
||||
|
||||
var matchmakeSession match_making_types.MatchmakeSession
|
||||
|
||||
if anyGathering.Object.GatheringObjectID().Equals(types.NewString("MatchmakeSession")) {
|
||||
matchmakeSession = anyGathering.Object.(match_making_types.MatchmakeSession)
|
||||
} else {
|
||||
common_globals.Logger.Critical("Non-MatchmakeSession DataType?!")
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if !common_globals.CheckValidMatchmakeSession(matchmakeSession) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
nexError := database.CreateMatchmakeSession(commonProtocol.manager, connection, &matchmakeSession)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
participants, nexError := database.JoinMatchmakeSession(commonProtocol.manager, matchmakeSession, connection, uint16(participationCount), string(message))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
matchmakeSession.ParticipationCount = types.NewUInt32(participants)
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
matchmakeSession.Gathering.ID.WriteTo(rmcResponseStream)
|
||||
|
||||
if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.0.0") {
|
||||
matchmakeSession.SessionKey.WriteTo(rmcResponseStream)
|
||||
}
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodCreateMatchmakeSession
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterCreateMatchmakeSession != nil {
|
||||
go commonProtocol.OnAfterCreateMatchmakeSession(packet, anyGathering, message, participationCount)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
80
matchmake-extension/create_matchmake_session_with_param.go
Normal file
80
matchmake-extension/create_matchmake_session_with_param.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if !common_globals.CheckValidMatchmakeSession(createMatchmakeSessionParam.SourceMatchmakeSession) {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(createMatchmakeSessionParam.JoinMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
if createMatchmakeSessionParam.GIDForParticipationCheck != 0 {
|
||||
// * Check that all new participants are participating in the specified gathering ID
|
||||
nexError := database.CheckGatheringForParticipation(commonProtocol.manager, uint32(createMatchmakeSessionParam.GIDForParticipationCheck), append(createMatchmakeSessionParam.AdditionalParticipants, connection.PID()))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
}
|
||||
|
||||
// * A client may disconnect from a session without leaving reliably,
|
||||
// * so let's make sure the client is removed from all sessions
|
||||
database.EndMatchmakeSessionsParticipation(commonProtocol.manager, connection)
|
||||
|
||||
joinedMatchmakeSession := createMatchmakeSessionParam.SourceMatchmakeSession.Copy().(match_making_types.MatchmakeSession)
|
||||
nexError := database.CreateMatchmakeSession(commonProtocol.manager, connection, &joinedMatchmakeSession)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
participants, nexError := database.JoinMatchmakeSessionWithParticipants(commonProtocol.manager, joinedMatchmakeSession, connection, createMatchmakeSessionParam.AdditionalParticipants, string(createMatchmakeSessionParam.JoinMessage), constants.JoinMatchmakeSessionBehaviorJoinMyself)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
joinedMatchmakeSession.ParticipationCount = types.NewUInt32(participants)
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
joinedMatchmakeSession.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodCreateMatchmakeSessionWithParam
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterCreateMatchmakeSessionWithParam != nil {
|
||||
go commonProtocol.OnAfterCreateMatchmakeSessionWithParam(packet, createMatchmakeSessionParam)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
)
|
||||
|
||||
// CheckGatheringForParticipation checks that the given PIDs are participating on the gathering ID
|
||||
func CheckGatheringForParticipation(manager *common_globals.MatchmakingManager, gatheringID uint32, participantsCheck []types.PID) *nex.Error {
|
||||
_, _, participants, _, err := database.FindGatheringByID(manager, gatheringID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, participant := range participantsCheck {
|
||||
if !slices.Contains(participants, uint64(participant)) {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.NotParticipatedGathering, "change_error")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
100
matchmake-extension/database/create_matchmake_session.go
Normal file
100
matchmake-extension/database/create_matchmake_session.go
Normal file
|
@ -0,0 +1,100 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// CreateMatchmakeSession creates a new MatchmakeSession on the database. No participants are added
|
||||
func CreateMatchmakeSession(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, matchmakeSession *match_making_types.MatchmakeSession) *nex.Error {
|
||||
startedTime, nexError := match_making_database.RegisterGathering(manager, connection.PID(), connection.PID(), &matchmakeSession.Gathering, "MatchmakeSession")
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
attribs := make([]uint32, len(matchmakeSession.Attributes))
|
||||
for i, value := range matchmakeSession.Attributes {
|
||||
attribs[i] = uint32(value)
|
||||
}
|
||||
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
matchmakeParam := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
srVariant := types.NewVariant()
|
||||
srVariant.TypeID = 3
|
||||
srVariant.Type = types.NewBool(true)
|
||||
matchmakeSession.MatchmakeParam.Params["@SR"] = srVariant
|
||||
girVariant := types.NewVariant()
|
||||
girVariant.TypeID = 1
|
||||
girVariant.Type = types.NewInt64(3)
|
||||
matchmakeSession.MatchmakeParam.Params["@GIR"] = girVariant
|
||||
|
||||
matchmakeSession.MatchmakeParam.WriteTo(matchmakeParam)
|
||||
|
||||
matchmakeSession.StartedTime = startedTime
|
||||
matchmakeSession.SessionKey = make([]byte, 32)
|
||||
matchmakeSession.SystemPasswordEnabled = false
|
||||
rand.Read(matchmakeSession.SessionKey)
|
||||
|
||||
_, err := manager.Database.Exec(`INSERT INTO matchmaking.matchmake_sessions (
|
||||
id,
|
||||
game_mode,
|
||||
attribs,
|
||||
open_participation,
|
||||
matchmake_system_type,
|
||||
application_buffer,
|
||||
progress_score,
|
||||
session_key,
|
||||
option_zero,
|
||||
matchmake_param,
|
||||
user_password,
|
||||
refer_gid,
|
||||
user_password_enabled,
|
||||
system_password_enabled,
|
||||
codeword
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8,
|
||||
$9,
|
||||
$10,
|
||||
$11,
|
||||
$12,
|
||||
$13,
|
||||
$14,
|
||||
$15
|
||||
)`,
|
||||
matchmakeSession.Gathering.ID,
|
||||
matchmakeSession.GameMode,
|
||||
pqextended.Array(attribs),
|
||||
matchmakeSession.OpenParticipation,
|
||||
matchmakeSession.MatchmakeSystemType,
|
||||
matchmakeSession.ApplicationBuffer,
|
||||
matchmakeSession.ProgressScore,
|
||||
matchmakeSession.SessionKey,
|
||||
matchmakeSession.Option,
|
||||
matchmakeParam.Bytes(),
|
||||
matchmakeSession.UserPassword,
|
||||
matchmakeSession.ReferGID,
|
||||
matchmakeSession.UserPasswordEnabled,
|
||||
matchmakeSession.SystemPasswordEnabled,
|
||||
matchmakeSession.CodeWord,
|
||||
)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
54
matchmake-extension/database/create_persistent_gathering.go
Normal file
54
matchmake-extension/database/create_persistent_gathering.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// CreatePersistentGathering creates a new PersistentGathering on the database. No participants are added
|
||||
func CreatePersistentGathering(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, persistentGathering *match_making_types.PersistentGathering) *nex.Error {
|
||||
_, nexError := match_making_database.RegisterGathering(manager, connection.PID(), types.NewPID(0), &persistentGathering.Gathering, "PersistentGathering")
|
||||
if nexError != nil {
|
||||
return nexError
|
||||
}
|
||||
|
||||
attribs := make([]uint32, len(persistentGathering.Attribs))
|
||||
for i, value := range persistentGathering.Attribs {
|
||||
attribs[i] = uint32(value)
|
||||
}
|
||||
|
||||
_, err := manager.Database.Exec(`INSERT INTO matchmaking.persistent_gatherings (
|
||||
id,
|
||||
community_type,
|
||||
password,
|
||||
attribs,
|
||||
application_buffer,
|
||||
participation_start_date,
|
||||
participation_end_date
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
)`,
|
||||
uint32(persistentGathering.Gathering.ID),
|
||||
uint32(persistentGathering.CommunityType),
|
||||
string(persistentGathering.Password),
|
||||
pqextended.Array(attribs),
|
||||
[]byte(persistentGathering.ApplicationBuffer),
|
||||
persistentGathering.ParticipationStartDate.Standard(),
|
||||
persistentGathering.ParticipationEndDate.Standard(),
|
||||
)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
)
|
||||
|
||||
// EndMatchmakeSessionsParticipation ends participation on all matchmake sessions
|
||||
func EndMatchmakeSessionsParticipation(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection) {
|
||||
rows, err := manager.Database.Query(`SELECT id FROM matchmaking.gatherings WHERE type='MatchmakeSession' AND $1=ANY(participants)`, connection.PID())
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
var gatheringID uint32
|
||||
err = rows.Scan(&gatheringID)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
database.EndGatheringParticipation(manager, gatheringID, connection, "")
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
}
|
145
matchmake-extension/database/find_matchmake_session.go
Normal file
145
matchmake-extension/database/find_matchmake_session.go
Normal file
|
@ -0,0 +1,145 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// FindMatchmakeSession finds a matchmake session with the given search matchmake session
|
||||
func FindMatchmakeSession(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, searchMatchmakeSession match_making_types.MatchmakeSession) (*match_making_types.MatchmakeSession, *nex.Error) {
|
||||
attribs := make([]uint32, len(searchMatchmakeSession.Attributes))
|
||||
for i, value := range searchMatchmakeSession.Attributes {
|
||||
attribs[i] = uint32(value)
|
||||
}
|
||||
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
searchStatement := `SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
array_length(g.participants, 1),
|
||||
g.started_time,
|
||||
ms.game_mode,
|
||||
ms.attribs,
|
||||
ms.open_participation,
|
||||
ms.matchmake_system_type,
|
||||
ms.application_buffer,
|
||||
ms.progress_score,
|
||||
ms.session_key,
|
||||
ms.option_zero,
|
||||
ms.matchmake_param,
|
||||
ms.user_password,
|
||||
ms.refer_gid,
|
||||
ms.user_password_enabled,
|
||||
ms.system_password_enabled,
|
||||
ms.codeword
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.matchmake_sessions AS ms ON ms.id = g.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='MatchmakeSession' AND
|
||||
g.host_pid <> 0 AND
|
||||
ms.open_participation=true AND
|
||||
array_length(g.participants, 1) < g.max_participants AND
|
||||
ms.user_password_enabled=false AND
|
||||
ms.system_password_enabled=false AND
|
||||
g.max_participants=$1 AND
|
||||
g.min_participants=$2 AND
|
||||
ms.game_mode=$3 AND
|
||||
ms.attribs[1]=$4 AND
|
||||
ms.attribs[3]=$6 AND
|
||||
ms.attribs[4]=$7 AND
|
||||
ms.attribs[5]=$8 AND
|
||||
ms.attribs[6]=$9 AND
|
||||
ms.matchmake_system_type=$10 AND
|
||||
ms.codeword=$11 AND (CASE WHEN g.participation_policy=98 THEN g.owner_pid=ANY($12) ELSE true END)
|
||||
ORDER BY abs($5 - ms.attribs[2])` // * Use "Closest attribute" selection method, guessing from Mario Kart 7
|
||||
|
||||
var friendList []uint32
|
||||
// * Prevent access to friend rooms if not implemented
|
||||
if manager.GetUserFriendPIDs != nil {
|
||||
friendList = manager.GetUserFriendPIDs(uint32(connection.PID()))
|
||||
}
|
||||
|
||||
resultMatchmakeSession := match_making_types.NewMatchmakeSession()
|
||||
var startedTime time.Time
|
||||
var resultAttribs []uint32
|
||||
var resultMatchmakeParam []byte
|
||||
|
||||
// * For simplicity, we will only compare the values that exist on a MatchmakeSessionSearchCriteria
|
||||
err := manager.Database.QueryRow(searchStatement,
|
||||
searchMatchmakeSession.Gathering.MaximumParticipants,
|
||||
searchMatchmakeSession.Gathering.MinimumParticipants,
|
||||
searchMatchmakeSession.GameMode,
|
||||
attribs[0],
|
||||
attribs[1],
|
||||
attribs[2],
|
||||
attribs[3],
|
||||
attribs[4],
|
||||
attribs[5],
|
||||
searchMatchmakeSession.MatchmakeSystemType,
|
||||
searchMatchmakeSession.CodeWord,
|
||||
pqextended.Array(friendList),
|
||||
).Scan(
|
||||
&resultMatchmakeSession.Gathering.ID,
|
||||
&resultMatchmakeSession.Gathering.OwnerPID,
|
||||
&resultMatchmakeSession.Gathering.HostPID,
|
||||
&resultMatchmakeSession.Gathering.MinimumParticipants,
|
||||
&resultMatchmakeSession.Gathering.MaximumParticipants,
|
||||
&resultMatchmakeSession.Gathering.ParticipationPolicy,
|
||||
&resultMatchmakeSession.Gathering.PolicyArgument,
|
||||
&resultMatchmakeSession.Gathering.Flags,
|
||||
&resultMatchmakeSession.Gathering.State,
|
||||
&resultMatchmakeSession.Gathering.Description,
|
||||
&resultMatchmakeSession.ParticipationCount,
|
||||
&startedTime,
|
||||
&resultMatchmakeSession.GameMode,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultMatchmakeSession.OpenParticipation,
|
||||
&resultMatchmakeSession.MatchmakeSystemType,
|
||||
&resultMatchmakeSession.ApplicationBuffer,
|
||||
&resultMatchmakeSession.ProgressScore,
|
||||
&resultMatchmakeSession.SessionKey,
|
||||
&resultMatchmakeSession.Option,
|
||||
&resultMatchmakeParam,
|
||||
&resultMatchmakeSession.UserPassword,
|
||||
&resultMatchmakeSession.ReferGID,
|
||||
&resultMatchmakeSession.UserPasswordEnabled,
|
||||
&resultMatchmakeSession.SystemPasswordEnabled,
|
||||
&resultMatchmakeSession.CodeWord,
|
||||
)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
resultMatchmakeSession.StartedTime = resultMatchmakeSession.StartedTime.FromTimestamp(startedTime)
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultMatchmakeSession.Attributes = attributesSlice
|
||||
|
||||
matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes)
|
||||
|
||||
return &resultMatchmakeSession, nil
|
||||
}
|
|
@ -0,0 +1,360 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// FindMatchmakeSessionBySearchCriteria finds matchmake sessions with the given search criterias
|
||||
func FindMatchmakeSessionBySearchCriteria(manager *common_globals.MatchmakingManager, connection *nex.PRUDPConnection, searchCriterias []match_making_types.MatchmakeSessionSearchCriteria, resultRange types.ResultRange, sourceMatchmakeSession *match_making_types.MatchmakeSession) ([]match_making_types.MatchmakeSession, *nex.Error) {
|
||||
resultMatchmakeSessions := make([]match_making_types.MatchmakeSession, 0)
|
||||
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
var friendList []uint32
|
||||
if manager.GetUserFriendPIDs != nil {
|
||||
friendList = manager.GetUserFriendPIDs(uint32(connection.PID()))
|
||||
}
|
||||
|
||||
if resultRange.Offset == math.MaxUint32 {
|
||||
resultRange.Offset = 0
|
||||
}
|
||||
|
||||
for _, searchCriteria := range searchCriterias {
|
||||
searchStatement := `SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
array_length(g.participants, 1),
|
||||
g.started_time,
|
||||
ms.game_mode,
|
||||
ms.attribs,
|
||||
ms.open_participation,
|
||||
ms.matchmake_system_type,
|
||||
ms.application_buffer,
|
||||
ms.progress_score,
|
||||
ms.session_key,
|
||||
ms.option_zero,
|
||||
ms.matchmake_param,
|
||||
ms.user_password,
|
||||
ms.refer_gid,
|
||||
ms.user_password_enabled,
|
||||
ms.system_password_enabled,
|
||||
ms.codeword
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.matchmake_sessions AS ms ON ms.id = g.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='MatchmakeSession' AND
|
||||
ms.refer_gid=$1 AND
|
||||
ms.codeword=$2 AND
|
||||
array_length(ms.attribs, 1)=$3 AND
|
||||
(CASE WHEN g.participation_policy=98 THEN g.owner_pid=ANY($4) ELSE true END) AND
|
||||
(CASE WHEN $5=true THEN ms.open_participation=true ELSE true END) AND
|
||||
(CASE WHEN $6=true THEN g.host_pid <> 0 ELSE true END) AND
|
||||
(CASE WHEN $7=true THEN ms.user_password_enabled=false ELSE true END) AND
|
||||
(CASE WHEN $8=true THEN ms.system_password_enabled=false ELSE true END)`
|
||||
|
||||
var valid bool = true
|
||||
for i, attrib := range searchCriteria.Attribs {
|
||||
// * Ignore attribute 1 here, reserved for the selection method
|
||||
if i == 1 {
|
||||
continue;
|
||||
}
|
||||
|
||||
if attrib != "" {
|
||||
before, after, found := strings.Cut(string(attrib), ",")
|
||||
if found {
|
||||
min, err := strconv.ParseUint(before, 10, 32)
|
||||
if err != nil {
|
||||
valid = false
|
||||
break
|
||||
}
|
||||
|
||||
max, err := strconv.ParseUint(after, 10, 32)
|
||||
if err != nil {
|
||||
valid = false
|
||||
break
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND ms.attribs[%d] BETWEEN %d AND %d`, i + 1, min, max)
|
||||
} else {
|
||||
value, err := strconv.ParseUint(before, 10, 32)
|
||||
if err != nil {
|
||||
valid = false
|
||||
break
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND ms.attribs[%d]=%d`, i + 1, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * Search criteria is invalid, continue to next one
|
||||
if !valid {
|
||||
continue
|
||||
}
|
||||
|
||||
if searchCriteria.MaxParticipants != "" {
|
||||
before, after, found := strings.Cut(string(searchCriteria.MaxParticipants), ",")
|
||||
if found {
|
||||
min, err := strconv.ParseUint(before, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
max, err := strconv.ParseUint(after, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND g.max_participants BETWEEN %d AND %d`, min, max)
|
||||
} else {
|
||||
value, err := strconv.ParseUint(before, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND g.max_participants=%d`, value)
|
||||
}
|
||||
}
|
||||
|
||||
if searchCriteria.MinParticipants != "" {
|
||||
before, after, found := strings.Cut(string(searchCriteria.MinParticipants), ",")
|
||||
if found {
|
||||
min, err := strconv.ParseUint(before, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
max, err := strconv.ParseUint(after, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND g.min_participants BETWEEN %d AND %d`, min, max)
|
||||
} else {
|
||||
value, err := strconv.ParseUint(before, 10, 16)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND g.min_participants=%d`, value)
|
||||
}
|
||||
}
|
||||
|
||||
if searchCriteria.GameMode != "" {
|
||||
before, after, found := strings.Cut(string(searchCriteria.GameMode), ",")
|
||||
if found {
|
||||
min, err := strconv.ParseUint(before, 10, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
max, err := strconv.ParseUint(after, 10, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND ms.game_mode BETWEEN %d AND %d`, min, max)
|
||||
} else {
|
||||
value, err := strconv.ParseUint(before, 10, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND ms.game_mode=%d`, value)
|
||||
}
|
||||
}
|
||||
|
||||
if searchCriteria.MatchmakeSystemType != "" {
|
||||
before, after, found := strings.Cut(string(searchCriteria.MatchmakeSystemType), ",")
|
||||
if found {
|
||||
min, err := strconv.ParseUint(before, 10, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
max, err := strconv.ParseUint(after, 10, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND ms.matchmake_system_type BETWEEN %d AND %d`, min, max)
|
||||
} else {
|
||||
value, err := strconv.ParseUint(before, 10, 32)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` AND ms.matchmake_system_type=%d`, value)
|
||||
}
|
||||
}
|
||||
|
||||
// * Filter full sessions if necessary
|
||||
if searchCriteria.VacantOnly {
|
||||
// * Account for the VacantParticipants when searching for sessions (if given)
|
||||
if searchCriteria.VacantParticipants == 0 {
|
||||
searchStatement += ` AND array_length(g.participants, 1) + 1 <= g.max_participants`
|
||||
} else {
|
||||
searchStatement += fmt.Sprintf(` AND array_length(g.participants, 1) + %d <= g.max_participants`, searchCriteria.VacantParticipants)
|
||||
}
|
||||
}
|
||||
|
||||
switch constants.SelectionMethod(searchCriteria.SelectionMethod) {
|
||||
case constants.SelectionMethodRandom:
|
||||
// * Random global
|
||||
searchStatement += ` ORDER BY RANDOM()`
|
||||
case constants.SelectionMethodNearestNeighbor:
|
||||
// * Closest attribute
|
||||
attribute1, err := strconv.ParseUint(string(searchCriteria.Attribs[1]), 10, 32)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.attribs[2])`, attribute1)
|
||||
case constants.SelectionMethodBroadenRange:
|
||||
// * Ranked
|
||||
|
||||
// TODO - Actually implement ranked matchmaking, using closest attribute at the moment
|
||||
attribute1, err := strconv.ParseUint(string(searchCriteria.Attribs[1]), 10, 32)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.attribs[2])`, attribute1)
|
||||
case constants.SelectionMethodProgressScore:
|
||||
// * Progress Score
|
||||
|
||||
// * We can only use this when doing auto-matchmake
|
||||
if sourceMatchmakeSession == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.progress_score)`, sourceMatchmakeSession.ProgressScore)
|
||||
case constants.SelectionMethodBroadenRangeWithProgressScore:
|
||||
// * Ranked + Progress
|
||||
|
||||
// TODO - Actually implement ranked matchmaking, using closest attribute at the moment
|
||||
|
||||
// * We can only use this when doing auto-matchmake
|
||||
if sourceMatchmakeSession == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if searchCriteria.Attribs[1] != "" {
|
||||
attribute1, err := strconv.ParseUint(string(searchCriteria.Attribs[1]), 10, 32)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO - Should the attribute and the progress score actually weigh the same?
|
||||
searchStatement += fmt.Sprintf(` ORDER BY abs(%d - ms.attribs[2] + %d - ms.progress_score)`, attribute1, sourceMatchmakeSession.ProgressScore)
|
||||
}
|
||||
|
||||
// case constants.SelectionMethodScoreBased: // * According to notes this is related with the MatchmakeParam. TODO - Implement this
|
||||
}
|
||||
|
||||
// * If the ResultRange inside the MatchmakeSessionSearchCriteria is valid (only present on NEX 4.0+), use that
|
||||
// * Otherwise, use the one given as argument
|
||||
if searchCriteria.ResultRange.Length != 0 {
|
||||
searchStatement += fmt.Sprintf(` LIMIT %d OFFSET %d`, uint32(searchCriteria.ResultRange.Length), uint32(searchCriteria.ResultRange.Offset))
|
||||
} else {
|
||||
// * Since we use one ResultRange for all searches, limit the total length to the one specified
|
||||
// * but apply the same offset to all queries
|
||||
searchStatement += fmt.Sprintf(` LIMIT %d OFFSET %d`, uint32(resultRange.Length) - uint32(len(resultMatchmakeSessions)), uint32(resultRange.Offset))
|
||||
}
|
||||
|
||||
rows, err := manager.Database.Query(searchStatement,
|
||||
searchCriteria.ReferGID,
|
||||
searchCriteria.CodeWord,
|
||||
len(searchCriteria.Attribs),
|
||||
pqextended.Array(friendList),
|
||||
searchCriteria.ExcludeLocked,
|
||||
searchCriteria.ExcludeNonHostPID,
|
||||
searchCriteria.ExcludeUserPasswordSet,
|
||||
searchCriteria.ExcludeSystemPasswordSet,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
resultMatchmakeSession := match_making_types.NewMatchmakeSession()
|
||||
var startedTime time.Time
|
||||
var resultAttribs []uint32
|
||||
var resultMatchmakeParam []byte
|
||||
|
||||
err = rows.Scan(
|
||||
&resultMatchmakeSession.Gathering.ID,
|
||||
&resultMatchmakeSession.Gathering.OwnerPID,
|
||||
&resultMatchmakeSession.Gathering.HostPID,
|
||||
&resultMatchmakeSession.Gathering.MinimumParticipants,
|
||||
&resultMatchmakeSession.Gathering.MaximumParticipants,
|
||||
&resultMatchmakeSession.Gathering.ParticipationPolicy,
|
||||
&resultMatchmakeSession.Gathering.PolicyArgument,
|
||||
&resultMatchmakeSession.Gathering.Flags,
|
||||
&resultMatchmakeSession.Gathering.State,
|
||||
&resultMatchmakeSession.Gathering.Description,
|
||||
&resultMatchmakeSession.ParticipationCount,
|
||||
&startedTime,
|
||||
&resultMatchmakeSession.GameMode,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultMatchmakeSession.OpenParticipation,
|
||||
&resultMatchmakeSession.MatchmakeSystemType,
|
||||
&resultMatchmakeSession.ApplicationBuffer,
|
||||
&resultMatchmakeSession.ProgressScore,
|
||||
&resultMatchmakeSession.SessionKey,
|
||||
&resultMatchmakeSession.Option,
|
||||
&resultMatchmakeParam,
|
||||
&resultMatchmakeSession.UserPassword,
|
||||
&resultMatchmakeSession.ReferGID,
|
||||
&resultMatchmakeSession.UserPasswordEnabled,
|
||||
&resultMatchmakeSession.SystemPasswordEnabled,
|
||||
&resultMatchmakeSession.CodeWord,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
resultMatchmakeSession.StartedTime = resultMatchmakeSession.StartedTime.FromTimestamp(startedTime)
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultMatchmakeSession.Attributes = attributesSlice
|
||||
|
||||
matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes)
|
||||
|
||||
resultMatchmakeSessions = append(resultMatchmakeSessions, resultMatchmakeSession)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
}
|
||||
|
||||
return resultMatchmakeSessions, nil
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// GetCreatedPersistentGatherings returns the number of active persistent gatherings that a given PID owns
|
||||
func GetCreatedPersistentGatherings(manager *common_globals.MatchmakingManager, ownerPID types.PID) (int, *nex.Error) {
|
||||
var createdPersistentGatherings int
|
||||
err := manager.Database.QueryRow(`SELECT
|
||||
COUNT(pg.id)
|
||||
FROM matchmaking.persistent_gatherings AS pg
|
||||
INNER JOIN matchmaking.gatherings AS g ON g.id = pg.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.owner_pid=$1`, ownerPID).Scan(&createdPersistentGatherings)
|
||||
if err != nil {
|
||||
return 0, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return createdPersistentGatherings, nil
|
||||
}
|
47
matchmake-extension/database/get_detailed_gathering_by_id.go
Normal file
47
matchmake-extension/database/get_detailed_gathering_by_id.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
)
|
||||
|
||||
// GetDetailedGatheringByID returns a Gathering as an RVType by its gathering ID
|
||||
func GetDetailedGatheringByID(manager *common_globals.MatchmakingManager, sourcePID uint64, gatheringID uint32) (types.RVType, string, *nex.Error) {
|
||||
gathering, gatheringType, participants, startedTime, nexError := match_making_database.FindGatheringByID(manager, gatheringID)
|
||||
if nexError != nil {
|
||||
return nil, "", nexError
|
||||
}
|
||||
|
||||
if gatheringType == "Gathering" {
|
||||
return gathering, gatheringType, nil
|
||||
}
|
||||
|
||||
if gatheringType == "MatchmakeSession" {
|
||||
matchmakeSession, nexError := GetMatchmakeSessionByGathering(manager, manager.Endpoint, gathering, uint32(len(participants)), startedTime)
|
||||
if nexError != nil {
|
||||
return nil, "", nexError
|
||||
}
|
||||
|
||||
// * Scrap session key and user password
|
||||
matchmakeSession.SessionKey = make([]byte, 0)
|
||||
matchmakeSession.UserPassword = ""
|
||||
|
||||
return matchmakeSession, gatheringType, nil
|
||||
}
|
||||
|
||||
if gatheringType == "PersistentGathering" {
|
||||
persistentGathering, nexError := GetPersistentGatheringByGathering(manager, gathering, sourcePID)
|
||||
if nexError != nil {
|
||||
return nil, "", nexError
|
||||
}
|
||||
|
||||
// * Scrap persistent gathering password
|
||||
persistentGathering.Password = ""
|
||||
|
||||
return persistentGathering, gatheringType, nil
|
||||
}
|
||||
|
||||
return nil, "", nex.NewError(nex.ResultCodes.Core.Exception, "change_error")
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetMatchmakeSessionByGathering gets a matchmake session with the given gathering data
|
||||
func GetMatchmakeSessionByGathering(manager *common_globals.MatchmakingManager, endpoint *nex.PRUDPEndPoint, gathering match_making_types.Gathering, participationCount uint32, startedTime types.DateTime) (match_making_types.MatchmakeSession, *nex.Error) {
|
||||
resultMatchmakeSession := match_making_types.NewMatchmakeSession()
|
||||
var resultAttribs []uint32
|
||||
var resultMatchmakeParam []byte
|
||||
|
||||
err := manager.Database.QueryRow(`SELECT
|
||||
game_mode,
|
||||
attribs,
|
||||
open_participation,
|
||||
matchmake_system_type,
|
||||
application_buffer,
|
||||
progress_score,
|
||||
session_key,
|
||||
option_zero,
|
||||
matchmake_param,
|
||||
user_password,
|
||||
refer_gid,
|
||||
user_password_enabled,
|
||||
system_password_enabled,
|
||||
codeword
|
||||
FROM matchmaking.matchmake_sessions WHERE id=$1`,
|
||||
uint32(gathering.ID),
|
||||
).Scan(
|
||||
&resultMatchmakeSession.GameMode,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultMatchmakeSession.OpenParticipation,
|
||||
&resultMatchmakeSession.MatchmakeSystemType,
|
||||
&resultMatchmakeSession.ApplicationBuffer,
|
||||
&resultMatchmakeSession.ProgressScore,
|
||||
&resultMatchmakeSession.SessionKey,
|
||||
&resultMatchmakeSession.Option,
|
||||
&resultMatchmakeParam,
|
||||
&resultMatchmakeSession.UserPassword,
|
||||
&resultMatchmakeSession.ReferGID,
|
||||
&resultMatchmakeSession.UserPasswordEnabled,
|
||||
&resultMatchmakeSession.SystemPasswordEnabled,
|
||||
&resultMatchmakeSession.CodeWord,
|
||||
)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return match_making_types.NewMatchmakeSession(), nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
} else {
|
||||
return match_making_types.NewMatchmakeSession(), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
resultMatchmakeSession.Gathering = gathering
|
||||
resultMatchmakeSession.ParticipationCount = types.NewUInt32(participationCount)
|
||||
resultMatchmakeSession.StartedTime = startedTime
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultMatchmakeSession.Attributes = attributesSlice
|
||||
|
||||
matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes)
|
||||
|
||||
return resultMatchmakeSession, nil
|
||||
}
|
107
matchmake-extension/database/get_matchmake_session_by_id.go
Normal file
107
matchmake-extension/database/get_matchmake_session_by_id.go
Normal file
|
@ -0,0 +1,107 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetMatchmakeSessionByID gets a matchmake session with the given gathering ID and the system password
|
||||
func GetMatchmakeSessionByID(manager *common_globals.MatchmakingManager, endpoint *nex.PRUDPEndPoint, gatheringID uint32) (match_making_types.MatchmakeSession, string, *nex.Error) {
|
||||
resultMatchmakeSession := match_making_types.NewMatchmakeSession()
|
||||
var startedTime time.Time
|
||||
var resultAttribs []uint32
|
||||
var resultMatchmakeParam []byte
|
||||
var systemPassword string
|
||||
|
||||
// * For simplicity, we will only compare the values that exist on a MatchmakeSessionSearchCriteria
|
||||
err := manager.Database.QueryRow(`SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
array_length(g.participants, 1),
|
||||
g.started_time,
|
||||
ms.game_mode,
|
||||
ms.attribs,
|
||||
ms.open_participation,
|
||||
ms.matchmake_system_type,
|
||||
ms.application_buffer,
|
||||
ms.progress_score,
|
||||
ms.session_key,
|
||||
ms.option_zero,
|
||||
ms.matchmake_param,
|
||||
ms.user_password,
|
||||
ms.refer_gid,
|
||||
ms.user_password_enabled,
|
||||
ms.system_password_enabled,
|
||||
ms.codeword,
|
||||
ms.system_password
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.matchmake_sessions AS ms ON ms.id = g.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='MatchmakeSession' AND
|
||||
g.id=$1`,
|
||||
gatheringID,
|
||||
).Scan(
|
||||
&resultMatchmakeSession.Gathering.ID,
|
||||
&resultMatchmakeSession.Gathering.OwnerPID,
|
||||
&resultMatchmakeSession.Gathering.HostPID,
|
||||
&resultMatchmakeSession.Gathering.MinimumParticipants,
|
||||
&resultMatchmakeSession.Gathering.MaximumParticipants,
|
||||
&resultMatchmakeSession.Gathering.ParticipationPolicy,
|
||||
&resultMatchmakeSession.Gathering.PolicyArgument,
|
||||
&resultMatchmakeSession.Gathering.Flags,
|
||||
&resultMatchmakeSession.Gathering.State,
|
||||
&resultMatchmakeSession.Gathering.Description,
|
||||
&resultMatchmakeSession.ParticipationCount,
|
||||
&startedTime,
|
||||
&resultMatchmakeSession.GameMode,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultMatchmakeSession.OpenParticipation,
|
||||
&resultMatchmakeSession.MatchmakeSystemType,
|
||||
&resultMatchmakeSession.ApplicationBuffer,
|
||||
&resultMatchmakeSession.ProgressScore,
|
||||
&resultMatchmakeSession.SessionKey,
|
||||
&resultMatchmakeSession.Option,
|
||||
&resultMatchmakeParam,
|
||||
&resultMatchmakeSession.UserPassword,
|
||||
&resultMatchmakeSession.ReferGID,
|
||||
&resultMatchmakeSession.UserPasswordEnabled,
|
||||
&resultMatchmakeSession.SystemPasswordEnabled,
|
||||
&resultMatchmakeSession.CodeWord,
|
||||
&systemPassword,
|
||||
)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return match_making_types.NewMatchmakeSession(), "", nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
} else {
|
||||
return match_making_types.NewMatchmakeSession(), "", nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
resultMatchmakeSession.StartedTime = resultMatchmakeSession.StartedTime.FromTimestamp(startedTime)
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultMatchmakeSession.Attributes = attributesSlice
|
||||
|
||||
matchmakeParamBytes := nex.NewByteStreamIn(resultMatchmakeParam, endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
resultMatchmakeSession.MatchmakeParam.ExtractFrom(matchmakeParamBytes)
|
||||
|
||||
return resultMatchmakeSession, systemPassword, nil
|
||||
}
|
60
matchmake-extension/database/get_notification_datas.go
Normal file
60
matchmake-extension/database/get_notification_datas.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetNotificationDatas gets the notification datas that belong to friends of the user and match with any of the given types
|
||||
func GetNotificationDatas(manager *common_globals.MatchmakingManager, sourcePID types.PID, notificationTypes []uint32) ([]notifications_types.NotificationEvent, *nex.Error) {
|
||||
dataList := make([]notifications_types.NotificationEvent, 0)
|
||||
|
||||
var friendList []uint32
|
||||
if manager.GetUserFriendPIDs != nil {
|
||||
friendList = manager.GetUserFriendPIDs(uint32(sourcePID))
|
||||
} else {
|
||||
common_globals.Logger.Warning("GetNotificationDatas missing manager.GetUserFriendPIDs!")
|
||||
}
|
||||
|
||||
// * No friends to check
|
||||
if len(friendList) == 0 {
|
||||
return dataList, nil
|
||||
}
|
||||
|
||||
rows, err := manager.Database.Query(`SELECT
|
||||
source_pid,
|
||||
type,
|
||||
param_1,
|
||||
param_2,
|
||||
param_str
|
||||
FROM matchmaking.notifications WHERE active=true AND source_pid=ANY($1) AND type=ANY($2)
|
||||
`, pqextended.Array(friendList), pqextended.Array(notificationTypes))
|
||||
if err != nil {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
notificationData := notifications_types.NewNotificationEvent()
|
||||
|
||||
err = rows.Scan(
|
||||
¬ificationData.PIDSource,
|
||||
¬ificationData.Type,
|
||||
¬ificationData.Param1,
|
||||
¬ificationData.Param2,
|
||||
¬ificationData.StrParam,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
dataList = append(dataList, notificationData)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
|
||||
return dataList, nil
|
||||
}
|
114
matchmake-extension/database/get_official_communities.go
Normal file
114
matchmake-extension/database/get_official_communities.go
Normal file
|
@ -0,0 +1,114 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetOfficialCommunities returns the official communities based on the given parameters
|
||||
func GetOfficialCommunities(manager *common_globals.MatchmakingManager, sourcePID types.PID, isAvailableOnly bool, resultRange types.ResultRange) ([]match_making_types.PersistentGathering, *nex.Error) {
|
||||
persistentGatherings := make([]match_making_types.PersistentGathering, 0)
|
||||
currentTime := time.Now().UTC()
|
||||
timeNever := types.NewDateTime(0).Standard()
|
||||
rows, err := manager.Database.Query(`SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
pg.community_type,
|
||||
pg.password,
|
||||
pg.attribs,
|
||||
pg.application_buffer,
|
||||
pg.participation_start_date,
|
||||
pg.participation_end_date,
|
||||
(SELECT COUNT(ms.id)
|
||||
FROM matchmaking.matchmake_sessions AS ms
|
||||
INNER JOIN matchmaking.gatherings AS gms ON ms.id = gms.id
|
||||
WHERE gms.registered=true
|
||||
AND ms.matchmake_system_type=5 -- matchmake_system_type=5 is only used in matchmake sessions attached to a persistent gathering
|
||||
AND ms.attribs[1]=g.id) AS matchmake_session_count,
|
||||
COALESCE((SELECT cp.participation_count
|
||||
FROM matchmaking.community_participations AS cp
|
||||
WHERE cp.user_pid=$5
|
||||
AND cp.gathering_id=g.id), 0) AS participation_count
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.persistent_gatherings AS pg ON g.id = pg.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='PersistentGathering' AND
|
||||
pg.community_type=2 AND
|
||||
(CASE WHEN $1 THEN
|
||||
(CASE WHEN pg.participation_start_date <> $6 THEN $2 >= pg.participation_start_date ELSE true END)
|
||||
AND
|
||||
(CASE WHEN pg.participation_end_date <> $6 THEN $2 <= pg.participation_end_date ELSE true END)
|
||||
ELSE true END)
|
||||
LIMIT $3 OFFSET $4`,
|
||||
isAvailableOnly,
|
||||
currentTime,
|
||||
uint32(resultRange.Length),
|
||||
uint32(resultRange.Offset),
|
||||
sourcePID,
|
||||
timeNever,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
resultPersistentGathering := match_making_types.NewPersistentGathering()
|
||||
var resultAttribs []uint32
|
||||
var resultParticipationStartDate time.Time
|
||||
var resultParticipationEndDate time.Time
|
||||
|
||||
err = rows.Scan(
|
||||
&resultPersistentGathering.Gathering.ID,
|
||||
&resultPersistentGathering.Gathering.OwnerPID,
|
||||
&resultPersistentGathering.Gathering.HostPID,
|
||||
&resultPersistentGathering.Gathering.MinimumParticipants,
|
||||
&resultPersistentGathering.Gathering.MaximumParticipants,
|
||||
&resultPersistentGathering.Gathering.ParticipationPolicy,
|
||||
&resultPersistentGathering.Gathering.PolicyArgument,
|
||||
&resultPersistentGathering.Gathering.Flags,
|
||||
&resultPersistentGathering.Gathering.State,
|
||||
&resultPersistentGathering.Gathering.Description,
|
||||
&resultPersistentGathering.CommunityType,
|
||||
&resultPersistentGathering.Password,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultPersistentGathering.ApplicationBuffer,
|
||||
&resultParticipationStartDate,
|
||||
&resultParticipationEndDate,
|
||||
&resultPersistentGathering.MatchmakeSessionCount,
|
||||
&resultPersistentGathering.ParticipationCount,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultPersistentGathering.Attribs = attributesSlice
|
||||
|
||||
resultPersistentGathering.ParticipationStartDate = resultPersistentGathering.ParticipationStartDate.FromTimestamp(resultParticipationStartDate)
|
||||
resultPersistentGathering.ParticipationEndDate = resultPersistentGathering.ParticipationEndDate.FromTimestamp(resultParticipationEndDate)
|
||||
|
||||
persistentGatherings = append(persistentGatherings, resultPersistentGathering)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
|
||||
return persistentGatherings, nil
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetPersistentGatheringByGathering gets a persistent gathering with the given gathering data
|
||||
func GetPersistentGatheringByGathering(manager *common_globals.MatchmakingManager, gathering match_making_types.Gathering, sourcePID uint64) (match_making_types.PersistentGathering, *nex.Error) {
|
||||
resultPersistentGathering := match_making_types.NewPersistentGathering()
|
||||
var resultAttribs []uint32
|
||||
var resultParticipationStartDate time.Time
|
||||
var resultParticipationEndDate time.Time
|
||||
|
||||
err := manager.Database.QueryRow(`SELECT
|
||||
community_type,
|
||||
password,
|
||||
attribs,
|
||||
application_buffer,
|
||||
participation_start_date,
|
||||
participation_end_date,
|
||||
(SELECT COUNT(ms.id)
|
||||
FROM matchmaking.matchmake_sessions AS ms
|
||||
INNER JOIN matchmaking.gatherings AS gms ON ms.id = gms.id
|
||||
WHERE gms.registered=true
|
||||
AND ms.matchmake_system_type=5 -- matchmake_system_type=5 is only used in matchmake sessions attached to a persistent gathering
|
||||
AND ms.attribs[1]=g.id) AS matchmake_session_count,
|
||||
COALESCE((SELECT cp.participation_count
|
||||
FROM matchmaking.community_participations AS cp
|
||||
WHERE cp.user_pid=$2
|
||||
AND cp.gathering_id=g.id), 0) AS participation_count
|
||||
FROM matchmaking.persistent_gatherings
|
||||
WHERE id=$1`,
|
||||
gathering.ID,
|
||||
sourcePID,
|
||||
).Scan(
|
||||
&resultPersistentGathering.CommunityType,
|
||||
&resultPersistentGathering.Password,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultPersistentGathering.ApplicationBuffer,
|
||||
&resultParticipationStartDate,
|
||||
&resultParticipationEndDate,
|
||||
&resultPersistentGathering.MatchmakeSessionCount,
|
||||
&resultPersistentGathering.ParticipationCount,
|
||||
)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return match_making_types.NewPersistentGathering(), nex.NewError(nex.ResultCodes.RendezVous.InvalidGID, "change_error")
|
||||
} else {
|
||||
return match_making_types.NewPersistentGathering(), nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
resultPersistentGathering.Gathering = gathering
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultPersistentGathering.Attribs = attributesSlice
|
||||
|
||||
resultPersistentGathering.ParticipationStartDate = resultPersistentGathering.ParticipationStartDate.FromTimestamp(resultParticipationStartDate)
|
||||
resultPersistentGathering.ParticipationEndDate = resultPersistentGathering.ParticipationEndDate.FromTimestamp(resultParticipationEndDate)
|
||||
|
||||
return resultPersistentGathering, nil
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetPersistentGatheringByID gets the persistent gatherings from the given gathering IDs
|
||||
func GetPersistentGatheringByID(manager *common_globals.MatchmakingManager, sourcePID types.PID, gatheringID uint32) (match_making_types.PersistentGathering, *nex.Error) {
|
||||
resultPersistentGathering := match_making_types.NewPersistentGathering()
|
||||
var resultAttribs []uint32
|
||||
var resultParticipationStartDate time.Time
|
||||
var resultParticipationEndDate time.Time
|
||||
|
||||
err := manager.Database.QueryRow(`SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
pg.community_type,
|
||||
pg.password,
|
||||
pg.attribs,
|
||||
pg.application_buffer,
|
||||
pg.participation_start_date,
|
||||
pg.participation_end_date,
|
||||
(SELECT COUNT(ms.id)
|
||||
FROM matchmaking.matchmake_sessions AS ms
|
||||
INNER JOIN matchmaking.gatherings AS gms ON ms.id = gms.id
|
||||
WHERE gms.registered=true
|
||||
AND ms.matchmake_system_type=5 -- matchmake_system_type=5 is only used in matchmake sessions attached to a persistent gathering
|
||||
AND ms.attribs[1]=g.id) AS matchmake_session_count,
|
||||
COALESCE((SELECT cp.participation_count
|
||||
FROM matchmaking.community_participations AS cp
|
||||
WHERE cp.user_pid=$2
|
||||
AND cp.gathering_id=g.id), 0) AS participation_count
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.persistent_gatherings AS pg ON g.id = pg.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='PersistentGathering' AND
|
||||
g.id=$1`,
|
||||
gatheringID,
|
||||
sourcePID,
|
||||
).Scan(
|
||||
&resultPersistentGathering.Gathering.ID,
|
||||
&resultPersistentGathering.Gathering.OwnerPID,
|
||||
&resultPersistentGathering.Gathering.HostPID,
|
||||
&resultPersistentGathering.Gathering.MinimumParticipants,
|
||||
&resultPersistentGathering.Gathering.MaximumParticipants,
|
||||
&resultPersistentGathering.Gathering.ParticipationPolicy,
|
||||
&resultPersistentGathering.Gathering.PolicyArgument,
|
||||
&resultPersistentGathering.Gathering.Flags,
|
||||
&resultPersistentGathering.Gathering.State,
|
||||
&resultPersistentGathering.Gathering.Description,
|
||||
&resultPersistentGathering.CommunityType,
|
||||
&resultPersistentGathering.Password,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultPersistentGathering.ApplicationBuffer,
|
||||
&resultParticipationStartDate,
|
||||
&resultParticipationEndDate,
|
||||
&resultPersistentGathering.MatchmakeSessionCount,
|
||||
&resultPersistentGathering.ParticipationCount,
|
||||
)
|
||||
if err != nil {
|
||||
return match_making_types.NewPersistentGathering(), nil
|
||||
}
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultPersistentGathering.Attribs = attributesSlice
|
||||
|
||||
resultPersistentGathering.ParticipationStartDate = resultPersistentGathering.ParticipationStartDate.FromTimestamp(resultParticipationStartDate)
|
||||
resultPersistentGathering.ParticipationEndDate = resultPersistentGathering.ParticipationEndDate.FromTimestamp(resultParticipationEndDate)
|
||||
|
||||
return resultPersistentGathering, nil
|
||||
}
|
102
matchmake-extension/database/get_persistent_gatherings_by_id.go
Normal file
102
matchmake-extension/database/get_persistent_gatherings_by_id.go
Normal file
|
@ -0,0 +1,102 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetPersistentGatheringsByID gets the persistent gatherings from the given gathering IDs
|
||||
func GetPersistentGatheringsByID(manager *common_globals.MatchmakingManager, sourcePID types.PID, gatheringIDs []uint32) ([]match_making_types.PersistentGathering, *nex.Error) {
|
||||
persistentGatherings := make([]match_making_types.PersistentGathering, 0)
|
||||
rows, err := manager.Database.Query(`SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
pg.community_type,
|
||||
pg.password,
|
||||
pg.attribs,
|
||||
pg.application_buffer,
|
||||
pg.participation_start_date,
|
||||
pg.participation_end_date,
|
||||
(SELECT COUNT(ms.id)
|
||||
FROM matchmaking.matchmake_sessions AS ms
|
||||
INNER JOIN matchmaking.gatherings AS gms ON ms.id = gms.id
|
||||
WHERE gms.registered=true
|
||||
AND ms.matchmake_system_type=5 -- matchmake_system_type=5 is only used in matchmake sessions attached to a persistent gathering
|
||||
AND ms.attribs[1]=g.id) AS matchmake_session_count,
|
||||
COALESCE((SELECT cp.participation_count
|
||||
FROM matchmaking.community_participations AS cp
|
||||
WHERE cp.user_pid=$2
|
||||
AND cp.gathering_id=g.id), 0) AS participation_count
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.persistent_gatherings AS pg ON g.id = pg.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='PersistentGathering' AND
|
||||
g.id=ANY($1)`,
|
||||
pqextended.Array(gatheringIDs),
|
||||
sourcePID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
resultPersistentGathering := match_making_types.NewPersistentGathering()
|
||||
var resultAttribs []uint32
|
||||
var resultParticipationStartDate time.Time
|
||||
var resultParticipationEndDate time.Time
|
||||
|
||||
err = rows.Scan(
|
||||
&resultPersistentGathering.Gathering.ID,
|
||||
&resultPersistentGathering.Gathering.OwnerPID,
|
||||
&resultPersistentGathering.Gathering.HostPID,
|
||||
&resultPersistentGathering.Gathering.MinimumParticipants,
|
||||
&resultPersistentGathering.Gathering.MaximumParticipants,
|
||||
&resultPersistentGathering.Gathering.ParticipationPolicy,
|
||||
&resultPersistentGathering.Gathering.PolicyArgument,
|
||||
&resultPersistentGathering.Gathering.Flags,
|
||||
&resultPersistentGathering.Gathering.State,
|
||||
&resultPersistentGathering.Gathering.Description,
|
||||
&resultPersistentGathering.CommunityType,
|
||||
&resultPersistentGathering.Password,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultPersistentGathering.ApplicationBuffer,
|
||||
&resultParticipationStartDate,
|
||||
&resultParticipationEndDate,
|
||||
&resultPersistentGathering.MatchmakeSessionCount,
|
||||
&resultPersistentGathering.ParticipationCount,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultPersistentGathering.Attribs = attributesSlice
|
||||
|
||||
resultPersistentGathering.ParticipationStartDate = resultPersistentGathering.ParticipationStartDate.FromTimestamp(resultParticipationStartDate)
|
||||
resultPersistentGathering.ParticipationEndDate = resultPersistentGathering.ParticipationEndDate.FromTimestamp(resultParticipationEndDate)
|
||||
|
||||
persistentGatherings = append(persistentGatherings, resultPersistentGathering)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
|
||||
return persistentGatherings, nil
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetPersistentGatheringsByParticipant finds the active persistent gatherings that a user is participating on
|
||||
func GetPersistentGatheringsByParticipant(manager *common_globals.MatchmakingManager, sourcePID types.PID, participant types.PID, resultRange types.ResultRange) ([]match_making_types.PersistentGathering, *nex.Error) {
|
||||
persistentGatherings := make([]match_making_types.PersistentGathering, 0)
|
||||
rows, err := manager.Database.Query(`SELECT
|
||||
g.id,
|
||||
g.owner_pid,
|
||||
g.host_pid,
|
||||
g.min_participants,
|
||||
g.max_participants,
|
||||
g.participation_policy,
|
||||
g.policy_argument,
|
||||
g.flags,
|
||||
g.state,
|
||||
g.description,
|
||||
pg.community_type,
|
||||
pg.password,
|
||||
pg.attribs,
|
||||
pg.application_buffer,
|
||||
pg.participation_start_date,
|
||||
pg.participation_end_date,
|
||||
(SELECT COUNT(ms.id)
|
||||
FROM matchmaking.matchmake_sessions AS ms
|
||||
INNER JOIN matchmaking.gatherings AS gms ON ms.id = gms.id
|
||||
WHERE gms.registered=true
|
||||
AND ms.matchmake_system_type=5 -- matchmake_system_type=5 is only used in matchmake sessions attached to a persistent gathering
|
||||
AND ms.attribs[1]=g.id) AS matchmake_session_count,
|
||||
COALESCE((SELECT cp.participation_count
|
||||
FROM matchmaking.community_participations AS cp
|
||||
WHERE cp.user_pid=$4
|
||||
AND cp.gathering_id=g.id), 0) AS participation_count
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.persistent_gatherings AS pg ON g.id = pg.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='PersistentGathering' AND
|
||||
$1=ANY(g.participants)
|
||||
LIMIT $2 OFFSET $3`,
|
||||
participant,
|
||||
resultRange.Length,
|
||||
resultRange.Offset,
|
||||
sourcePID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
resultPersistentGathering := match_making_types.NewPersistentGathering()
|
||||
var resultAttribs []uint32
|
||||
var resultParticipationStartDate time.Time
|
||||
var resultParticipationEndDate time.Time
|
||||
|
||||
err = rows.Scan(
|
||||
&resultPersistentGathering.Gathering.ID,
|
||||
&resultPersistentGathering.Gathering.OwnerPID,
|
||||
&resultPersistentGathering.Gathering.HostPID,
|
||||
&resultPersistentGathering.Gathering.MinimumParticipants,
|
||||
&resultPersistentGathering.Gathering.MaximumParticipants,
|
||||
&resultPersistentGathering.Gathering.ParticipationPolicy,
|
||||
&resultPersistentGathering.Gathering.PolicyArgument,
|
||||
&resultPersistentGathering.Gathering.Flags,
|
||||
&resultPersistentGathering.Gathering.State,
|
||||
&resultPersistentGathering.Gathering.Description,
|
||||
&resultPersistentGathering.CommunityType,
|
||||
&resultPersistentGathering.Password,
|
||||
pqextended.Array(&resultAttribs),
|
||||
&resultPersistentGathering.ApplicationBuffer,
|
||||
&resultParticipationStartDate,
|
||||
&resultParticipationEndDate,
|
||||
&resultPersistentGathering.MatchmakeSessionCount,
|
||||
&resultPersistentGathering.ParticipationCount,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
attributesSlice := make([]types.UInt32, len(resultAttribs))
|
||||
for i, value := range resultAttribs {
|
||||
attributesSlice[i] = types.NewUInt32(value)
|
||||
}
|
||||
resultPersistentGathering.Attribs = attributesSlice
|
||||
|
||||
resultPersistentGathering.ParticipationStartDate = resultPersistentGathering.ParticipationStartDate.FromTimestamp(resultParticipationStartDate)
|
||||
resultPersistentGathering.ParticipationEndDate = resultPersistentGathering.ParticipationEndDate.FromTimestamp(resultParticipationEndDate)
|
||||
|
||||
persistentGatherings = append(persistentGatherings, resultPersistentGathering)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
|
||||
return persistentGatherings, nil
|
||||
}
|
52
matchmake-extension/database/get_simple_communities.go
Normal file
52
matchmake-extension/database/get_simple_communities.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
pqextended "github.com/PretendoNetwork/pq-extended"
|
||||
)
|
||||
|
||||
// GetSimpleCommunities returns a slice of SimpleCommunity using information from the given gathering IDs
|
||||
func GetSimpleCommunities(manager *common_globals.MatchmakingManager, gatheringIDList []uint32) ([]match_making_types.SimpleCommunity, *nex.Error) {
|
||||
simpleCommunities := make([]match_making_types.SimpleCommunity, 0)
|
||||
|
||||
rows, err := manager.Database.Query(`SELECT
|
||||
pg.id,
|
||||
(SELECT COUNT(ms.id)
|
||||
FROM matchmaking.matchmake_sessions AS ms
|
||||
INNER JOIN matchmaking.gatherings AS gms ON ms.id = gms.id
|
||||
WHERE gms.registered=true
|
||||
AND ms.matchmake_system_type=5 -- matchmake_system_type=5 is only used in matchmake sessions attached to a persistent gathering
|
||||
AND ms.attribs[1]=g.id) AS matchmake_session_count
|
||||
FROM matchmaking.persistent_gatherings AS pg
|
||||
INNER JOIN matchmaking.gatherings AS g ON g.id = pg.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='PersistentGathering' AND
|
||||
pg.id=ANY($1)`,
|
||||
pqextended.Array(gatheringIDList),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
resultSimpleCommunity := match_making_types.NewSimpleCommunity()
|
||||
|
||||
err = rows.Scan(
|
||||
&resultSimpleCommunity.GatheringID,
|
||||
&resultSimpleCommunity.MatchmakeSessionCount,
|
||||
)
|
||||
if err != nil {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
simpleCommunities = append(simpleCommunities, resultSimpleCommunity)
|
||||
}
|
||||
|
||||
rows.Close()
|
||||
|
||||
return simpleCommunities, nil
|
||||
}
|
44
matchmake-extension/database/get_simple_playing_session.go
Normal file
44
matchmake-extension/database/get_simple_playing_session.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
)
|
||||
|
||||
// GetSimplePlayingSession returns the simple playing sessions of the given PIDs
|
||||
func GetSimplePlayingSession(manager *common_globals.MatchmakingManager, listPID []types.PID) ([]match_making_types.SimplePlayingSession, *nex.Error) {
|
||||
simplePlayingSessions := make([]match_making_types.SimplePlayingSession, 0)
|
||||
for _, pid := range listPID {
|
||||
simplePlayingSession := match_making_types.NewSimplePlayingSession()
|
||||
|
||||
err := manager.Database.QueryRow(`SELECT
|
||||
g.id,
|
||||
ms.attribs[1],
|
||||
ms.game_mode
|
||||
FROM matchmaking.gatherings AS g
|
||||
INNER JOIN matchmaking.matchmake_sessions AS ms ON ms.id = g.id
|
||||
WHERE
|
||||
g.registered=true AND
|
||||
g.type='MatchmakeSession' AND
|
||||
$1=ANY(g.participants)`, pid).Scan(
|
||||
&simplePlayingSession.GatheringID,
|
||||
&simplePlayingSession.Attribute0,
|
||||
&simplePlayingSession.GameMode)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
common_globals.Logger.Critical(err.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
simplePlayingSession.PrincipalID = pid
|
||||
|
||||
simplePlayingSessions = append(simplePlayingSessions, simplePlayingSession)
|
||||
}
|
||||
|
||||
return simplePlayingSessions, nil
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// InactivateNotificationDatas marks the notifications of a given user as inactive
|
||||
func InactivateNotificationDatas(manager *common_globals.MatchmakingManager, sourcePID types.PID) *nex.Error {
|
||||
_, err := manager.Database.Exec(`UPDATE matchmaking.notifications SET active=false WHERE source_pid=$1`, sourcePID)
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
42
matchmake-extension/database/join_matchmake_session.go
Normal file
42
matchmake-extension/database/join_matchmake_session.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/tracking"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
)
|
||||
|
||||
// JoinMatchmakeSession joins participants from the same connection into a MatchmakeSession. Returns the new number of participants
|
||||
func JoinMatchmakeSession(manager *common_globals.MatchmakingManager, matchmakeSession match_making_types.MatchmakeSession, connection *nex.PRUDPConnection, vacantParticipants uint16, joinMessage string) (uint32, *nex.Error) {
|
||||
newParticipants, nexError := match_making_database.JoinGathering(manager, uint32(matchmakeSession.ID), connection, vacantParticipants, joinMessage)
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
// TODO - Should we return the error in these cases?
|
||||
if uint32(matchmakeSession.MatchmakeSystemType) == uint32(constants.MatchmakeSystemTypePersistentGathering) { // * Attached to a persistent gathering
|
||||
persistentGatheringID := uint32(matchmakeSession.Attributes[0])
|
||||
_, nexError = GetPersistentGatheringByID(manager, connection.PID(), persistentGatheringID)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
return newParticipants, nil
|
||||
}
|
||||
|
||||
participationCount, nexError := UpdatePersistentGatheringParticipationCount(manager, connection.PID(), persistentGatheringID)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
return newParticipants, nil
|
||||
}
|
||||
|
||||
nexError = tracking.LogParticipateCommunity(manager.Database, connection.PID(), persistentGatheringID, uint32(matchmakeSession.ID), participationCount)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
return newParticipants, nil
|
||||
}
|
||||
}
|
||||
|
||||
return newParticipants, nil
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
match_making_database "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/tracking"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
)
|
||||
|
||||
// JoinMatchmakeSessionWithParticipants joins participants into a gathering. Returns the new number of participants
|
||||
func JoinMatchmakeSessionWithParticipants(manager *common_globals.MatchmakingManager, matchmakeSession match_making_types.MatchmakeSession, connection *nex.PRUDPConnection, additionalParticipants []types.PID, joinMessage string, joinMatchmakeSessionBehavior constants.JoinMatchmakeSessionBehavior) (uint32, *nex.Error) {
|
||||
newParticipants, nexError := match_making_database.JoinGatheringWithParticipants(manager, uint32(matchmakeSession.ID), connection, additionalParticipants, joinMessage, joinMatchmakeSessionBehavior)
|
||||
if nexError != nil {
|
||||
return 0, nexError
|
||||
}
|
||||
|
||||
// TODO - Should we return the error in these cases?
|
||||
if uint32(matchmakeSession.MatchmakeSystemType) == uint32(constants.MatchmakeSystemTypePersistentGathering) { // * Attached to a persistent gathering
|
||||
persistentGatheringID := uint32(matchmakeSession.Attributes[0])
|
||||
participantList := append(additionalParticipants, connection.PID())
|
||||
for _, participant := range participantList {
|
||||
_, nexError = GetPersistentGatheringByID(manager, participant, persistentGatheringID)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
participationCount, nexError := UpdatePersistentGatheringParticipationCount(manager, participant, persistentGatheringID)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
nexError = tracking.LogParticipateCommunity(manager.Database, participant, persistentGatheringID, uint32(matchmakeSession.ID), participationCount)
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return newParticipants, nil
|
||||
}
|
26
matchmake-extension/database/update_application_buffer.go
Normal file
26
matchmake-extension/database/update_application_buffer.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdateApplicationBuffer updates the application buffer of a matchmake session
|
||||
func UpdateApplicationBuffer(manager *common_globals.MatchmakingManager, gatheringID uint32, applicationBuffer types.Buffer) *nex.Error {
|
||||
result, err := manager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET application_buffer=$1 WHERE id=$2`, []byte(applicationBuffer), gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
25
matchmake-extension/database/update_game_attribute.go
Normal file
25
matchmake-extension/database/update_game_attribute.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdateGameAttribute updates an attribute on a matchmake session
|
||||
func UpdateGameAttribute(manager *common_globals.MatchmakingManager, gatheringID uint32, attributeIndex uint32, newValue uint32) *nex.Error {
|
||||
result, err := manager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET attribs[$1]=$2 WHERE id=$3`, attributeIndex + 1, newValue, gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
36
matchmake-extension/database/update_notification_data.go
Normal file
36
matchmake-extension/database/update_notification_data.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdateNotificationData updates the notification data of the specified user and type
|
||||
func UpdateNotificationData(manager *common_globals.MatchmakingManager, notificationData notifications_types.NotificationEvent) *nex.Error {
|
||||
_, err := manager.Database.Exec(`INSERT INTO matchmaking.notifications AS n (
|
||||
source_pid,
|
||||
type,
|
||||
param_1,
|
||||
param_2,
|
||||
param_str
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
) ON CONFLICT (source_pid, type) DO UPDATE SET
|
||||
param_1=$3, param_2=$4, param_str=$5, active=true WHERE n.source_pid=$1 AND n.type=$2`,
|
||||
notificationData.PIDSource,
|
||||
notificationData.Type,
|
||||
notificationData.Param1,
|
||||
notificationData.Param2,
|
||||
notificationData.StrParam,
|
||||
)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
25
matchmake-extension/database/update_participation.go
Normal file
25
matchmake-extension/database/update_participation.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdateParticipation updates the participation of a matchmake session
|
||||
func UpdateParticipation(manager *common_globals.MatchmakingManager, gatheringID uint32, participation bool) *nex.Error {
|
||||
result, err := manager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET open_participation=$1 WHERE id=$2`, participation, gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdatePersistentGatheringParticipationCount updates the participation count of a user in a persistent gathering. Returns the participation count
|
||||
func UpdatePersistentGatheringParticipationCount(manager *common_globals.MatchmakingManager, userPID types.PID, gatheringID uint32) (uint32, *nex.Error) {
|
||||
var participationCount uint32
|
||||
err := manager.Database.QueryRow(`INSERT INTO matchmaking.community_participations AS cp (
|
||||
user_pid,
|
||||
gathering_id,
|
||||
participation_count
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
1
|
||||
) ON CONFLICT (user_pid, gathering_id) DO UPDATE SET
|
||||
participation_count=cp.participation_count+1 RETURNING participation_count`,
|
||||
uint64(userPID),
|
||||
gatheringID,
|
||||
).Scan(&participationCount)
|
||||
if err != nil {
|
||||
return 0, nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
return participationCount, nil
|
||||
}
|
25
matchmake-extension/database/update_progress_score.go
Normal file
25
matchmake-extension/database/update_progress_score.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
)
|
||||
|
||||
// UpdateProgressScore updates the progress score on a matchmake session
|
||||
func UpdateProgressScore(manager *common_globals.MatchmakingManager, gatheringID uint32, progressScore uint8) *nex.Error {
|
||||
result, err := manager.Database.Exec(`UPDATE matchmaking.matchmake_sessions SET progress_score=$1 WHERE id=$2`, progressScore, gatheringID)
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
|
||||
}
|
||||
|
||||
if rowsAffected == 0 {
|
||||
return nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
61
matchmake-extension/find_community_by_gathering_id.go
Normal file
61
matchmake-extension/find_community_by_gathering_id.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) findCommunityByGatheringID(err error, packet nex.PacketInterface, callID uint32, lstGID types.List[types.UInt32]) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
var gatheringIDs []uint32
|
||||
for _, gatheringID := range lstGID {
|
||||
gatheringIDs = append(gatheringIDs, uint32(gatheringID))
|
||||
}
|
||||
|
||||
communities, nexError := database.GetPersistentGatheringsByID(commonProtocol.manager, connection.PID(), gatheringIDs)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
lstCommunity := types.NewList[match_making_types.PersistentGathering]()
|
||||
|
||||
for i := range communities {
|
||||
// * Scrap persistent gathering password
|
||||
communities[i].Password = ""
|
||||
}
|
||||
|
||||
lstCommunity = communities
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
lstCommunity.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodFindCommunityByGatheringID
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterFindCommunityByGatheringID != nil {
|
||||
go commonProtocol.OnAfterFindCommunityByGatheringID(packet, lstGID)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
56
matchmake-extension/find_community_by_participant.go
Normal file
56
matchmake-extension/find_community_by_participant.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) findCommunityByParticipant(err error, packet nex.PacketInterface, callID uint32, pid types.PID, resultRange types.ResultRange) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
communities, nexError := database.GetPersistentGatheringsByParticipant(commonProtocol.manager, connection.PID(), pid, resultRange)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
lstCommunity := types.NewList[match_making_types.PersistentGathering]()
|
||||
|
||||
for i := range communities {
|
||||
// * Scrap persistent gathering password
|
||||
communities[i].Password = ""
|
||||
}
|
||||
|
||||
lstCommunity = communities
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
lstCommunity.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodFindCommunityByParticipant
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterFindCommunityByParticipant != nil {
|
||||
go commonProtocol.OnAfterFindCommunityByParticipant(packet, pid, resultRange)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
56
matchmake-extension/find_official_community.go
Normal file
56
matchmake-extension/find_official_community.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) findOfficialCommunity(err error, packet nex.PacketInterface, callID uint32, isAvailableOnly types.Bool, resultRange types.ResultRange) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
communities, nexError := database.GetOfficialCommunities(commonProtocol.manager, connection.PID(), bool(isAvailableOnly), resultRange)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
lstCommunity := types.NewList[match_making_types.PersistentGathering]()
|
||||
|
||||
for i := range communities {
|
||||
// * Scrap persistent gathering password
|
||||
communities[i].Password = ""
|
||||
}
|
||||
|
||||
lstCommunity = communities
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
lstCommunity.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodFindOfficialCommunity
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterFindOfficialCommunity != nil {
|
||||
go commonProtocol.OnAfterFindOfficialCommunity(packet, isAvailableOnly, resultRange)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
56
matchmake-extension/get_friend_notification_data.go
Normal file
56
matchmake-extension/get_friend_notification_data.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getFriendNotificationData(err error, packet nex.PacketInterface, callID uint32, uiType types.Int32) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
// * This method can only receive notifications within the range 101-108, which are reserved for game-specific notifications
|
||||
if uiType < 101 || uiType > 108 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
notificationDatas, nexError := database.GetNotificationDatas(commonProtocol.manager, connection.PID(), []uint32{notifications.BuildNotificationType(uint32(uiType), 0)})
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
dataList := types.NewList[notifications_types.NotificationEvent]()
|
||||
dataList = notificationDatas
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
dataList.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodGetFriendNotificationData
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetFriendNotificationData != nil {
|
||||
go commonProtocol.OnAfterGetFriendNotificationData(packet, uiType)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
61
matchmake-extension/get_lst_friend_notification_data.go
Normal file
61
matchmake-extension/get_lst_friend_notification_data.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
|
||||
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getlstFriendNotificationData(err error, packet nex.PacketInterface, callID uint32, lstTypes types.List[types.UInt32]) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
notificationTypes := make([]uint32, len(lstTypes))
|
||||
for i, notificationType := range lstTypes {
|
||||
// * This method can only receive notifications within the range 101-108, which are reserved for game-specific notifications
|
||||
if notificationType < 101 || notificationType > 108 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
notificationTypes[i] = notifications.BuildNotificationType(uint32(notificationType), 0)
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
notificationDatas, nexError := database.GetNotificationDatas(commonProtocol.manager, connection.PID(), notificationTypes)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
dataList := types.NewList[notifications_types.NotificationEvent]()
|
||||
dataList = notificationDatas
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
dataList.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodGetlstFriendNotificationData
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetlstFriendNotificationData != nil {
|
||||
go commonProtocol.OnAfterGetlstFriendNotificationData(packet, lstTypes)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
55
matchmake-extension/get_simple_community.go
Normal file
55
matchmake-extension/get_simple_community.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getSimpleCommunity(err error, packet nex.PacketInterface, callID uint32, gatheringIDList types.List[types.UInt32]) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
var gatheringIDs []uint32
|
||||
for _, gatheringID := range gatheringIDList {
|
||||
gatheringIDs = append(gatheringIDs, uint32(gatheringID))
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
simpleCommunities, nexError := database.GetSimpleCommunities(commonProtocol.manager, gatheringIDs)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
lstSimpleCommunityList := types.NewList[match_making_types.SimpleCommunity]()
|
||||
lstSimpleCommunityList = simpleCommunities
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
lstSimpleCommunityList.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodGetSimpleCommunity
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetSimpleCommunity != nil {
|
||||
go commonProtocol.OnAfterGetSimpleCommunity(packet, gatheringIDList)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
61
matchmake-extension/get_simple_playing_session.go
Normal file
61
matchmake-extension/get_simple_playing_session.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) getSimplePlayingSession(err error, packet nex.PacketInterface, callID uint32, listPID types.List[types.PID], includeLoginUser types.Bool) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
// * Does nothing if element is not present in the List
|
||||
listPID = slices.DeleteFunc(listPID, func(pid types.PID) bool {
|
||||
return pid == connection.PID()
|
||||
})
|
||||
|
||||
if includeLoginUser {
|
||||
listPID = append(listPID, connection.PID())
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RLock()
|
||||
|
||||
simplePlayingSessions, nexError := database.GetSimplePlayingSession(commonProtocol.manager, listPID)
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.RUnlock()
|
||||
|
||||
lstSimplePlayingSession := types.NewList[match_making_types.SimplePlayingSession]()
|
||||
lstSimplePlayingSession = simplePlayingSessions
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
lstSimplePlayingSession.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodGetSimplePlayingSession
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterGetSimplePlayingSession != nil {
|
||||
go commonProtocol.OnAfterGetSimplePlayingSession(packet, listPID, includeLoginUser)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
78
matchmake-extension/join_matchmake_session.go
Normal file
78
matchmake-extension/join_matchmake_session.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, strMessage types.String) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(strMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
server := endpoint.Server
|
||||
|
||||
joinedMatchmakeSession, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
// TODO - Is this the correct error code?
|
||||
if joinedMatchmakeSession.UserPasswordEnabled || joinedMatchmakeSession.SystemPasswordEnabled {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
// * Allow game servers to do their own permissions checks
|
||||
if commonProtocol.CanJoinMatchmakeSession != nil {
|
||||
nexError = commonProtocol.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession)
|
||||
} else {
|
||||
nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession)
|
||||
}
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
_, nexError = database.JoinMatchmakeSession(commonProtocol.manager, joinedMatchmakeSession, connection, 1, string(strMessage))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.0.0") {
|
||||
joinedMatchmakeSession.SessionKey.WriteTo(rmcResponseStream)
|
||||
}
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSession
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterJoinMatchmakeSession != nil {
|
||||
go commonProtocol.OnAfterJoinMatchmakeSession(packet, gid, strMessage)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
78
matchmake-extension/join_matchmake_session_ex.go
Normal file
78
matchmake-extension/join_matchmake_session_ex.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, strMessage types.String, dontCareMyBlockList types.Bool, participationCount types.UInt16) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(strMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
server := endpoint.Server
|
||||
|
||||
joinedMatchmakeSession, _, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(gid))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
// TODO - Is this the correct error code?
|
||||
if joinedMatchmakeSession.UserPasswordEnabled || joinedMatchmakeSession.SystemPasswordEnabled {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error")
|
||||
}
|
||||
|
||||
// * Allow game servers to do their own permissions checks
|
||||
if commonProtocol.CanJoinMatchmakeSession != nil {
|
||||
nexError = commonProtocol.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession)
|
||||
} else {
|
||||
nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession)
|
||||
}
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
_, nexError = database.JoinMatchmakeSession(commonProtocol.manager, joinedMatchmakeSession, connection, uint16(participationCount), string(strMessage))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.0.0") {
|
||||
joinedMatchmakeSession.SessionKey.WriteTo(rmcResponseStream)
|
||||
}
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSessionEx
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterJoinMatchmakeSessionEx != nil {
|
||||
go commonProtocol.OnAfterJoinMatchmakeSessionEx(packet, gid, strMessage, dontCareMyBlockList, participationCount)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
90
matchmake-extension/join_matchmake_session_with_param.go
Normal file
90
matchmake-extension/join_matchmake_session_with_param.go
Normal file
|
@ -0,0 +1,90 @@
|
|||
package matchmake_extension
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/nex-go/v2"
|
||||
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
|
||||
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/v2/match-making/constants"
|
||||
match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types"
|
||||
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
|
||||
)
|
||||
|
||||
func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) {
|
||||
if err != nil {
|
||||
common_globals.Logger.Error(err.Error())
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
if len(joinMatchmakeSessionParam.JoinMessage) > 256 {
|
||||
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Lock()
|
||||
|
||||
connection := packet.Sender().(*nex.PRUDPConnection)
|
||||
endpoint := connection.Endpoint().(*nex.PRUDPEndPoint)
|
||||
|
||||
if joinMatchmakeSessionParam.GIDForParticipationCheck != 0 {
|
||||
// * Check that all new participants are participating in the specified gathering ID
|
||||
nexError := database.CheckGatheringForParticipation(commonProtocol.manager, uint32(joinMatchmakeSessionParam.GIDForParticipationCheck), append(joinMatchmakeSessionParam.AdditionalParticipants, connection.PID()))
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
}
|
||||
|
||||
joinedMatchmakeSession, systemPassword, nexError := database.GetMatchmakeSessionByID(commonProtocol.manager, endpoint, uint32(joinMatchmakeSessionParam.GID))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
// TODO - Are these the correct error codes?
|
||||
if bool(joinedMatchmakeSession.UserPasswordEnabled) && !joinMatchmakeSessionParam.StrUserPassword.Equals(joinedMatchmakeSession.UserPassword) {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidPassword, "change_error")
|
||||
}
|
||||
|
||||
if bool(joinedMatchmakeSession.SystemPasswordEnabled) && string(joinMatchmakeSessionParam.StrSystemPassword) != systemPassword {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidPassword, "change_error")
|
||||
}
|
||||
|
||||
// * Allow game servers to do their own permissions checks
|
||||
if commonProtocol.CanJoinMatchmakeSession != nil {
|
||||
nexError = commonProtocol.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession)
|
||||
} else {
|
||||
nexError = common_globals.CanJoinMatchmakeSession(commonProtocol.manager, connection.PID(), joinedMatchmakeSession)
|
||||
}
|
||||
if nexError != nil {
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
_, nexError = database.JoinMatchmakeSessionWithParticipants(commonProtocol.manager, joinedMatchmakeSession, connection, joinMatchmakeSessionParam.AdditionalParticipants, string(joinMatchmakeSessionParam.JoinMessage), constants.JoinMatchmakeSessionBehavior(joinMatchmakeSessionParam.JoinMatchmakeSessionBehavior))
|
||||
if nexError != nil {
|
||||
common_globals.Logger.Error(nexError.Error())
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
return nil, nexError
|
||||
}
|
||||
|
||||
commonProtocol.manager.Mutex.Unlock()
|
||||
|
||||
rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
|
||||
|
||||
joinedMatchmakeSession.WriteTo(rmcResponseStream)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody)
|
||||
rmcResponse.ProtocolID = matchmake_extension.ProtocolID
|
||||
rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSessionWithParam
|
||||
rmcResponse.CallID = callID
|
||||
|
||||
if commonProtocol.OnAfterJoinMatchmakeSessionWithParam != nil {
|
||||
go commonProtocol.OnAfterJoinMatchmakeSessionWithParam(packet, joinMatchmakeSessionParam)
|
||||
}
|
||||
|
||||
return rmcResponse, nil
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue