Initial commit
This commit is contained in:
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is 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. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
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.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
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 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. Use with the GNU Affero General Public License.
|
||||
|
||||
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 Affero 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 special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 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 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 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 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
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 GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,45 @@
|
||||
INCS= -Isrc/include -I../hm_base/src/include
|
||||
LIBS_PATH= -L../hm_base/lib/
|
||||
LIBS= -lhmbase
|
||||
CFLAGS+= -g
|
||||
|
||||
compile = $(CC) -c $(CFLAGS) $(INCS) $(LIBS_PATH) src/$(1).c -o src/$(1).o $(LIBS)
|
||||
|
||||
static: hmproto
|
||||
|
||||
hmproto:
|
||||
rm -rf lib/
|
||||
$(call compile,alloptions)
|
||||
$(call compile,bnet)
|
||||
$(call compile,chooseentities)
|
||||
$(call compile,chooseoption)
|
||||
$(call compile,creategame)
|
||||
$(call compile,packet)
|
||||
$(call compile,entity)
|
||||
$(call compile,entitychoices)
|
||||
$(call compile,game_entity)
|
||||
$(call compile,gamesetup)
|
||||
$(call compile,handshake)
|
||||
$(call compile,hide)
|
||||
$(call compile,meta)
|
||||
$(call compile,mouseinfo)
|
||||
$(call compile,option)
|
||||
$(call compile,platform)
|
||||
$(call compile,player)
|
||||
$(call compile,powerend)
|
||||
$(call compile,powerhistory)
|
||||
$(call compile,powerhistorydata)
|
||||
$(call compile,powerstart)
|
||||
$(call compile,proto)
|
||||
$(call compile,suboption)
|
||||
$(call compile,tag)
|
||||
$(call compile,tagchange)
|
||||
$(call compile,turntimer)
|
||||
$(call compile,userui)
|
||||
mkdir -p lib/
|
||||
ar cq lib/libhmproto.a src/*.o
|
||||
|
||||
clean:
|
||||
rm -rf src/*.o ./lib/
|
||||
|
||||
.PHONY: static hmproto
|
||||
@@ -0,0 +1,2 @@
|
||||
# hm_proto
|
||||
hearthmod proto
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void alloptions_free(struct alloptions_s *a)
|
||||
{
|
||||
struct option_s *o, *del;
|
||||
|
||||
for(o = a->options; o != NULL; del = o, o = o->next, option_free(del));
|
||||
|
||||
free(a);
|
||||
}
|
||||
|
||||
int alloptions_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
int n = 0;
|
||||
struct option_s *m;
|
||||
struct alloptions_s *s;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->id);
|
||||
|
||||
for(m = s->options; m != NULL; m = m->next) {
|
||||
write_byte(dst, maxdst, 18);
|
||||
n = option_size(m);
|
||||
write_uint(dst, maxdst, n);
|
||||
option_serialize(m, dst, maxdst);
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
int alloptions_size(struct alloptions_s *p)
|
||||
{
|
||||
int num = 0, n;
|
||||
struct option_s *s;
|
||||
|
||||
num += 1;
|
||||
num += sizeofu64(p->id);
|
||||
|
||||
for(s = p->options; s != NULL; s = s->next) {
|
||||
num += 1;
|
||||
n = option_size(s);
|
||||
num += sizeofu32(n) + n;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
void alloptions_dump(struct alloptions_s *a)
|
||||
{
|
||||
struct suboption_target_s *t;
|
||||
struct suboption_s *m;
|
||||
struct option_s *o;
|
||||
|
||||
hm_log(LOG_DEBUG, lg, "Dumping alloptions:");
|
||||
hm_log(LOG_DEBUG, lg, "id: %lld", a->id);
|
||||
for(o = a->options; o != NULL; o = o->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\tOption type: %lld", o->type);
|
||||
for(m = o->mainoption; m != NULL; m = m->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\tMainoption id: %lld", m->id);
|
||||
for(t = m->target; t != NULL; t = t->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\t\tTarget id: %lld", t->value);
|
||||
}
|
||||
}
|
||||
assert(o->suboptions == NULL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
int bnet_size(struct powerhistory_player_s *player)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if(player) {
|
||||
size += 2;
|
||||
size += sizeofu64(player->bnet_hi);
|
||||
size += sizeofu64(player->bnet_lo);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void chooseentities_free(struct chooseentities_s *c)
|
||||
{
|
||||
struct chooseentities_ent_s *e, *del;
|
||||
|
||||
for(e = c->entity; e != NULL; del = e, e = e->next, free(del));
|
||||
|
||||
free(c);
|
||||
}
|
||||
|
||||
int chooseentities_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct chooseentities_s *s;
|
||||
struct chooseentities_ent_s *e;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->id);
|
||||
|
||||
write_byte(dst, maxdst, 18);
|
||||
write_uint64(dst, maxdst, s->nentity);
|
||||
|
||||
for(e = s->entity; e != NULL; e = e->next) {
|
||||
write_uint(dst, maxdst, e->entity);
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
void *chooseentities_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, i;
|
||||
struct chooseentities_s *c;
|
||||
struct chooseentities_ent_s *e;
|
||||
|
||||
c = malloc(sizeof(*c));
|
||||
memset(c, 0, sizeof(*c));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
|
||||
c->id = read_uint64(dst, maxdst);
|
||||
c->entity = NULL;
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 18) {
|
||||
return c;
|
||||
}
|
||||
|
||||
c->nentity = read_uint(dst, maxdst);
|
||||
if(c->nentity > 5 || c->nentity < 0) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i < c->nentity && *dst < maxdst; i++) {
|
||||
e = malloc(sizeof(*e));
|
||||
e->entity = read_uint(dst, maxdst);
|
||||
e->next = c->entity;
|
||||
c->entity = e;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void chooseoption_free(struct chooseoption_s *c)
|
||||
{
|
||||
free(c);
|
||||
}
|
||||
|
||||
int chooseoption_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct chooseoption_s *s;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->id);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, s->index);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, s->target);
|
||||
|
||||
if(s->suboption != 0) {
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, s->suboption);
|
||||
}
|
||||
|
||||
if(s->position != 0) {
|
||||
write_byte(dst, maxdst, 40);
|
||||
write_uint64(dst, maxdst, s->position);
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
void *chooseoption_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct chooseoption_s *o;
|
||||
|
||||
o = malloc(sizeof(*o));
|
||||
memset(o, 0, sizeof(*o));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
o->id = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
o->index = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
o->target = read_uint64(dst, maxdst);
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 32) {
|
||||
o->suboption = read_uint64(dst, maxdst);
|
||||
} else if(n == 40) {
|
||||
o->position = read_uint64(dst, maxdst);
|
||||
} else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
void chooseoption_dump(struct chooseoption_s *o, u64 local_held_card)
|
||||
{
|
||||
hm_log(LOG_DEBUG, lg, "Choose options dump: option id: %lld index: %lld target: %lld suboption: %lld position: %lld local held card: %lld", o->id, o->index, o->target, o->suboption, o->position, local_held_card);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void creategame_free(struct powerhistory_creategame_s *c)
|
||||
{
|
||||
struct powerhistory_player_s *player, *del;
|
||||
|
||||
for(player = c->player; player != NULL; del = player, player = player->next, player_free(del));
|
||||
|
||||
free(c);
|
||||
}
|
||||
|
||||
struct powerhistory_creategame_s *creategame_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct powerhistory_creategame_s *t;
|
||||
struct powerhistory_player_s *player;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
t->player = t->player_tail = NULL;
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
|
||||
if(n != 10) {
|
||||
error();
|
||||
}
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
t->game_entity = game_entity_deserialize(dst, *dst + len);
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 18) {
|
||||
error();
|
||||
}
|
||||
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
player = player_deserialize(dst, *dst + len);
|
||||
player->next = NULL;
|
||||
|
||||
if(t->player == NULL && t->player_tail == NULL) {
|
||||
t->player = player;
|
||||
t->player_tail = player;
|
||||
} else {
|
||||
t->player_tail->next = player;
|
||||
t->player_tail = player;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int creategame_size(struct powerhistory_creategame_s *cg)
|
||||
{
|
||||
struct powerhistory_player_s *p;
|
||||
int num = 0;
|
||||
int n;
|
||||
|
||||
if(cg) {
|
||||
num += 1;
|
||||
n = game_entity_size(cg->game_entity);
|
||||
num += sizeofu32(n) + n;
|
||||
|
||||
for(p = cg->player; p != NULL; p = p->next) {
|
||||
num += 1;
|
||||
n = player_size(p);
|
||||
num += sizeofu32(n) + n;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int creategame_serialize(struct powerhistory_creategame_s *cg, char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct powerhistory_player_s *p;
|
||||
|
||||
write_byte(dst, maxdst, 10);
|
||||
n = game_entity_size(cg->game_entity);
|
||||
write_uint(dst, maxdst, n);
|
||||
game_entity_serialize(cg->game_entity, dst, maxdst);
|
||||
|
||||
for(p = cg->player; p != NULL; p = p->next) {
|
||||
write_byte(dst, maxdst, 18);
|
||||
n = player_size(p);
|
||||
write_uint(dst, maxdst, n);
|
||||
player_serialize(p, dst, maxdst);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void entity_free(struct powerhistory_entity_s *e)
|
||||
{
|
||||
struct powerhistory_tag_s *tag, *del;
|
||||
|
||||
for(tag = e->tag; tag != NULL; del = tag, tag = tag->next, tag_free(del));
|
||||
|
||||
//free(e->name);
|
||||
|
||||
free(e);
|
||||
}
|
||||
|
||||
struct powerhistory_entity_s *entity_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct powerhistory_entity_s *p;
|
||||
struct powerhistory_tag_s *t;
|
||||
|
||||
p = malloc(sizeof(*p));
|
||||
|
||||
p->tag = p->tag_tail = NULL;
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
|
||||
p->entity = read_uint64(dst, maxdst);
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 18) {
|
||||
error();
|
||||
}
|
||||
|
||||
p->name = read_bytes(dst, maxdst, &p->nname);
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
if(n == 26) {
|
||||
t = tag_deserialize(dst, *dst + len);
|
||||
t->next = NULL;
|
||||
|
||||
if(p->tag == NULL && p->tag_tail == NULL) {
|
||||
p->tag = t;
|
||||
p->tag_tail = t;
|
||||
} else {
|
||||
p->tag_tail->next = t;
|
||||
p->tag_tail = t;
|
||||
}
|
||||
} else {
|
||||
error();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
int entity_size(struct powerhistory_entity_s *ent)
|
||||
{
|
||||
int num = 0;
|
||||
int ts;
|
||||
struct powerhistory_tag_s *tag;
|
||||
|
||||
num += 2;
|
||||
num += sizeofu64(ent->entity);
|
||||
num += sizeofu32(ent->nname) + ent->nname;
|
||||
|
||||
for(tag = ent->tag; tag != NULL; tag = tag->next) {
|
||||
num += 1;
|
||||
ts = tag_size(tag);
|
||||
num += sizeofu32(ts) + ts;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int entity_serialize(struct powerhistory_entity_s *ent, char **dst, const char *maxdst)
|
||||
{
|
||||
int ts;
|
||||
struct powerhistory_tag_s *t;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, ent->entity);
|
||||
|
||||
write_byte(dst, maxdst, 18);
|
||||
write_bytes(dst, maxdst, ent->name, ent->nname);
|
||||
|
||||
if(ent->tag) {
|
||||
for(t = ent->tag; t != NULL; t = t->next) {
|
||||
write_byte(dst, maxdst, 26);
|
||||
ts = tag_size(t);
|
||||
write_uint(dst, maxdst, ts);
|
||||
tag_serialize(t, dst, maxdst);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void entitychoices_free(struct entitychoices_s *ec)
|
||||
{
|
||||
struct entitychoices_entities_s *e, *del;
|
||||
|
||||
for(e = ec->entities; e != NULL; del = e, e = e->next, free(del));
|
||||
|
||||
free(ec);
|
||||
}
|
||||
|
||||
void *entitychoices_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, i;
|
||||
struct entitychoices_s *o;
|
||||
struct entitychoices_entities_s *e = e;
|
||||
|
||||
o = malloc(sizeof(*o));
|
||||
memset(o, 0, sizeof(*o));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
o->id = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
o->type = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 32) {
|
||||
error();
|
||||
}
|
||||
o->countmin = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 40) {
|
||||
error();
|
||||
}
|
||||
o->countmax = read_uint64(dst, maxdst);
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 50) {
|
||||
int n = read_uint(dst, maxdst);
|
||||
for(i = 0; i < n; i++) {
|
||||
e = malloc(sizeof(*e));
|
||||
e->entity = read_uint64(dst, maxdst);
|
||||
e->next = o->entities;
|
||||
o->entities = e;
|
||||
}
|
||||
} else if(n == 56) {
|
||||
o->source = read_uint64(dst, maxdst);
|
||||
} else if(n == 64) {
|
||||
o->player_id = read_uint64(dst, maxdst);
|
||||
} else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
int entitychoices_serialize(void *ep, char **dst, const char *maxdst)
|
||||
{
|
||||
int n = 0;
|
||||
struct entitychoices_entities_s *es;
|
||||
struct entitychoices_s *e = ep;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, e->id);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, e->type);
|
||||
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, e->countmin);
|
||||
|
||||
write_byte(dst, maxdst, 40);
|
||||
write_uint64(dst, maxdst, e->countmax);
|
||||
|
||||
if(e->entities) {
|
||||
write_byte(dst, maxdst, 50);
|
||||
for(es = e->entities; es != NULL; es = es->next) {
|
||||
n += sizeofu64(es->entity);
|
||||
}
|
||||
|
||||
write_uint(dst, maxdst, n);
|
||||
|
||||
for(es = e->entities; es != NULL; es = es->next) {
|
||||
write_uint64(dst, maxdst, es->entity);
|
||||
}
|
||||
}
|
||||
|
||||
if(e->source > 0) {
|
||||
write_byte(dst, maxdst, 56);
|
||||
write_uint64(dst, maxdst, e->source);
|
||||
}
|
||||
|
||||
write_byte(dst, maxdst, 64);
|
||||
write_uint64(dst, maxdst, e->player_id);
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
void entitychoices_dump(struct entitychoices_s *es)
|
||||
{
|
||||
struct entitychoices_entities_s *ent;
|
||||
|
||||
hm_log(LOG_DEBUG, lg, "Entity Choices dump:");
|
||||
hm_log(LOG_DEBUG, lg, "\t\tID: %lld", es->id);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tType: %lld", es->type);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tCountMin: %lld", es->countmin);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tCountMax: %lld", es->countmax);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tSource: %lld", es->source);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tPlayer: %lld", es->player_id);
|
||||
|
||||
for(ent = es->entities; ent != NULL; ent = ent->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\t\tChild entity: %lld", ent->entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void game_entity_free(struct powerhistory_game_entity_s *g)
|
||||
{
|
||||
struct powerhistory_tag_s *tag, *del;
|
||||
|
||||
for(tag = g->tag; tag != NULL; del = tag, tag = tag->next, tag_free(del));
|
||||
|
||||
free(g);
|
||||
}
|
||||
|
||||
struct powerhistory_game_entity_s *game_entity_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct powerhistory_game_entity_s *t;
|
||||
struct powerhistory_tag_s *tag;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
memset(t, 0, sizeof(*t));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
|
||||
t->id = read_uint64(dst, maxdst);
|
||||
|
||||
while(*dst < maxdst) {
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 18) {
|
||||
error();
|
||||
}
|
||||
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
tag = tag_deserialize(dst, *dst + len);
|
||||
tag->next = NULL;
|
||||
|
||||
if(t->tag == NULL && t->tag_tail == NULL) {
|
||||
t->tag = tag;
|
||||
t->tag_tail = tag;
|
||||
} else {
|
||||
t->tag_tail->next = tag;
|
||||
t->tag_tail = tag;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int game_entity_serialize(struct powerhistory_game_entity_s *ent, char **dst, const char *maxdst)
|
||||
{
|
||||
int ts;
|
||||
struct powerhistory_tag_s *t;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, ent->id);
|
||||
|
||||
if(ent->tag) {
|
||||
for(t = ent->tag; t != NULL; t = t->next) {
|
||||
write_byte(dst, maxdst, 18);
|
||||
ts = tag_size(t);
|
||||
write_uint(dst, maxdst, ts);
|
||||
tag_serialize(t, dst, maxdst);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int game_entity_size(struct powerhistory_game_entity_s *ent)
|
||||
{
|
||||
int ts;
|
||||
struct powerhistory_tag_s *tag;
|
||||
int num = 0;
|
||||
|
||||
num += 1;
|
||||
num += sizeofu64(ent->id);
|
||||
|
||||
for(tag = ent->tag; tag != NULL; tag = tag->next) {
|
||||
num += 1;
|
||||
ts = tag_size(tag);
|
||||
num += sizeofu32(ts) + ts;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void gamesetup_free(struct gamesetup_s *g)
|
||||
{
|
||||
free(g);
|
||||
}
|
||||
|
||||
int gamesetup_serialize(void *data, char **dst, const char *maxdst)
|
||||
{
|
||||
char *start;
|
||||
struct gamesetup_s *g = data;
|
||||
|
||||
start = *dst;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, g->board);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, g->maxsecrets);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, g->maxfriendlyminions);
|
||||
|
||||
if(g->keepalive > 0) {
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, g->keepalive);
|
||||
}
|
||||
|
||||
if(g->stuckdisconnect > 0) {
|
||||
write_byte(dst, maxdst, 40);
|
||||
write_uint64(dst, maxdst, g->stuckdisconnect);
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
void *gamesetup_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct gamesetup_s *o;
|
||||
|
||||
o = malloc(sizeof(*o));
|
||||
memset(o, 0, sizeof(*o));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
o->board = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
o->maxsecrets = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
o->maxfriendlyminions = read_uint64(dst, maxdst);
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 32) {
|
||||
o->keepalive = read_uint64(dst, maxdst);
|
||||
} else if(n == 40) {
|
||||
o->stuckdisconnect = read_uint64(dst, maxdst);
|
||||
} else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
int gamesetup_size(struct gamesetup_s *g)
|
||||
{
|
||||
int num = 0;
|
||||
|
||||
num += 3;
|
||||
num += sizeofu64(g->board);
|
||||
num += sizeofu64(g->maxsecrets);
|
||||
num += sizeofu64(g->maxfriendlyminions);
|
||||
|
||||
if(g->keepalive > 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(g->keepalive);
|
||||
}
|
||||
|
||||
if(g->stuckdisconnect > 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(g->stuckdisconnect);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void handshake_free(struct handshake_s *h)
|
||||
{
|
||||
platform_free(h->platform);
|
||||
|
||||
free(h->version);
|
||||
free(h->password);
|
||||
|
||||
free(h);
|
||||
}
|
||||
|
||||
int handshake_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct handshake_s *s;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->gamehandle);
|
||||
|
||||
write_byte(dst, maxdst, 18);
|
||||
write_bytes(dst, maxdst, s->password, s->npassword);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, s->clienthandle);
|
||||
|
||||
if(s->mission != 0) {
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, s->mission);
|
||||
}
|
||||
|
||||
write_byte(dst, maxdst, 42);
|
||||
write_bytes(dst, maxdst, s->version, s->nversion);
|
||||
|
||||
write_byte(dst, maxdst, 58);
|
||||
write_uint(dst, maxdst, platform_size(s->platform));
|
||||
|
||||
platform_serialize(s->platform, dst, maxdst);
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
void *handshake_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct handshake_s *h;
|
||||
|
||||
h = malloc(sizeof(*h));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
h->gamehandle = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 18) {
|
||||
error();
|
||||
}
|
||||
h->password = read_bytes(dst, maxdst, &h->npassword);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
h->clienthandle = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 32) {
|
||||
h->mission = read_uint64(dst, maxdst);
|
||||
n = read_byte(dst, maxdst);
|
||||
}
|
||||
|
||||
if(n != 42) {
|
||||
error();
|
||||
}
|
||||
h->version = read_bytes(dst, maxdst, &h->nversion);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 58) {
|
||||
error();
|
||||
}
|
||||
len = read_uint(dst, maxdst);
|
||||
h->platform = platform_deserialize(dst, *dst + len);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
void handshake_dump(struct handshake_s *h)
|
||||
{
|
||||
hm_log(LOG_DEBUG, lg, "Gamehandle: %lld password: [%.*s] clienthandle: %lld mission: %lld verion: [%.*s] ", h->gamehandle, h->npassword, h->password, h->clienthandle, h->mission, h->nversion, h->version);
|
||||
if(h->platform) {
|
||||
hm_log(LOG_DEBUG, lg, "Os: %lld screen: %lld name: [%.*s] store: %lld", h->platform->os, h->platform->screen, h->platform->nname, h->platform->name, h->platform->store);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void hide_free(struct powerhistory_hide_s *t)
|
||||
{
|
||||
free(t);
|
||||
}
|
||||
|
||||
struct powerhistory_hide_s *hide_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct powerhistory_hide_s *t;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
t->entity = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
t->zone = read_uint64(dst, maxdst);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int hide_serialize(struct powerhistory_hide_s *ent, char **dst, const char *maxdst)
|
||||
{
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, ent->entity);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, ent->zone);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hide_size(struct powerhistory_hide_s *hide)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if(hide) {
|
||||
size += 2;
|
||||
size += sizeofu64(hide->entity);
|
||||
size += sizeofu64(hide->zone);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CHOOSEENTITIES_H_
|
||||
#define CHOOSEENTITIES_H_
|
||||
|
||||
struct chooseentities_ent_s {
|
||||
u64 entity;
|
||||
struct chooseentities_ent_s *next;
|
||||
};
|
||||
|
||||
struct chooseentities_s {
|
||||
u64 id;
|
||||
int nentity;
|
||||
struct chooseentities_ent_s *entity;
|
||||
};
|
||||
|
||||
void chooseentities_free(struct chooseentities_s *c);
|
||||
void *chooseentities_deserialize(char **dst, const char *maxdst);
|
||||
int chooseentities_serialize(void *ao, char **dst, const char *maxdst);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef ENTITYCHOICES_H_
|
||||
#define ENTITYCHOICES_H_
|
||||
|
||||
struct entitychoices_entities_s {
|
||||
u64 entity;
|
||||
struct entitychoices_entities_s *next;
|
||||
};
|
||||
|
||||
struct entitychoices_s {
|
||||
u64 id;
|
||||
u64 type;
|
||||
u64 countmin;
|
||||
u64 countmax;
|
||||
|
||||
u64 source;
|
||||
u64 player_id;
|
||||
|
||||
struct entitychoices_entities_s *entities;
|
||||
};
|
||||
|
||||
void entitychoices_free(struct entitychoices_s *ec);
|
||||
int entitychoices_serialize(void *ep, char **dst, const char *maxdst);
|
||||
void entitychoices_dump(struct entitychoices_s *es);
|
||||
void *entitychoices_deserialize(char **dst, const char *maxdst);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TAG_H_
|
||||
#define TAG_H_
|
||||
|
||||
enum gametag_e {
|
||||
TAG_SCRIPT_DATA_NUM_1 = 2,
|
||||
TAG_SCRIPT_DATA_NUM_2 = 3,
|
||||
TAG_SCRIPT_DATA_ENT_1 = 4,
|
||||
TAG_SCRIPT_DATA_ENT_2 = 5,
|
||||
MISSION_EVENT = 6,
|
||||
TIMEOUT = 7,
|
||||
TURN_START = 8,
|
||||
TURN_TIMER_SLUSH = 9,
|
||||
PREMIUM = 12,
|
||||
GOLD_REWARD_STATE = 13,
|
||||
PLAYSTATE = 17,
|
||||
LAST_AFFECTED_BY = 18,
|
||||
STEP = 19,
|
||||
TURN = 20,
|
||||
FATIGUE = 22,
|
||||
CURRENT_PLAYER = 23,
|
||||
FIRST_PLAYER = 24,
|
||||
RESOURCES_USED = 25,
|
||||
RESOURCES = 26,
|
||||
HERO_ENTITY = 27,
|
||||
MAXHANDSIZE = 28,
|
||||
STARTHANDSIZE = 29,
|
||||
PLAYER_ID = 30,
|
||||
TEAM_ID = 31,
|
||||
TRIGGER_VISUAL = 32,
|
||||
RECENTLY_ARRIVED = 33,
|
||||
PROTECTING = 34,
|
||||
PROTECTED = 35,
|
||||
DEFENDING = 36,
|
||||
PROPOSED_DEFENDER = 37,
|
||||
ATTACKING = 38,
|
||||
PROPOSED_ATTACKER = 39,
|
||||
ATTACHED = 40,
|
||||
EXHAUSTED = 43,
|
||||
DAMAGE = 44,
|
||||
HEALTH = 45,
|
||||
ATK = 47,
|
||||
COST = 48,
|
||||
ZONE = 49,
|
||||
CONTROLLER = 50,
|
||||
OWNER = 51,
|
||||
DEFINITION = 52,
|
||||
ENTITY_ID = 53,
|
||||
HISTORY_PROXY = 54,
|
||||
COPY_DEATHRATTLE = 55,
|
||||
ELITE = 114,
|
||||
MAXRESOURCES = 176,
|
||||
CARD_SET = 183,
|
||||
CARDTEXT_INHAND = 184,
|
||||
CARDNAME = 185,
|
||||
CARD_ID = 186,
|
||||
DURABILITY = 187,
|
||||
SILENCED = 188,
|
||||
WINDFURY = 189,
|
||||
TAUNT = 190,
|
||||
STEALTH = 191,
|
||||
SPELLPOWER = 192,
|
||||
DIVINE_SHIELD = 194,
|
||||
CHARGE = 197,
|
||||
NEXT_STEP = 198,
|
||||
CLASS = 199,
|
||||
CARDRACE = 200,
|
||||
FACTION = 201,
|
||||
CARDTYPE = 202,
|
||||
RARITY = 203,
|
||||
STATE = 204,
|
||||
SUMMONED = 205,
|
||||
FREEZE = 208,
|
||||
ENRAGED = 212,
|
||||
OVERLOAD = 215,
|
||||
LOYALTY = 216,
|
||||
DEATHRATTLE = 217,
|
||||
BATTLECRY = 218,
|
||||
SECRET = 219,
|
||||
COMBO = 220,
|
||||
CANT_HEAL = 221,
|
||||
CANT_DAMAGE = 222,
|
||||
CANT_SET_ASIDE = 223,
|
||||
CANT_REMOVE_FROM_GAME = 224,
|
||||
CANT_READY = 225,
|
||||
CANT_EXHAUST = 226,
|
||||
CANT_ATTACK = 227,
|
||||
CANT_TARGET = 228,
|
||||
CANT_DESTROY = 229,
|
||||
CANT_DISCARD = 230,
|
||||
CANT_PLAY = 231,
|
||||
CANT_DRAW = 232,
|
||||
INCOMING_HEALING_MULTIPLIER = 233,
|
||||
INCOMING_HEALING_ADJUSTMENT = 234,
|
||||
INCOMING_HEALING_CAP = 235,
|
||||
INCOMING_DAMAGE_MULTIPLIER = 236,
|
||||
INCOMING_DAMAGE_ADJUSTMENT = 237,
|
||||
INCOMING_DAMAGE_CAP = 238,
|
||||
CANT_BE_HEALED = 239,
|
||||
CANT_BE_DAMAGED = 240,
|
||||
CANT_BE_SET_ASIDE = 241,
|
||||
CANT_BE_REMOVED_FROM_GAME = 242,
|
||||
CANT_BE_READIED = 243,
|
||||
CANT_BE_EXHAUSTED = 244,
|
||||
CANT_BE_ATTACKED = 245,
|
||||
CANT_BE_TARGETED = 246,
|
||||
CANT_BE_DESTROYED = 247,
|
||||
CANT_BE_SUMMONING_SICK = 253,
|
||||
FROZEN = 260,
|
||||
JUST_PLAYED = 261,
|
||||
LINKEDCARD = 262,
|
||||
ZONE_POSITION = 263,
|
||||
CANT_BE_FROZEN = 264,
|
||||
COMBO_ACTIVE = 266,
|
||||
CARD_TARGET = 267,
|
||||
NUM_CARDS_PLAYED_THIS_TURN = 269,
|
||||
CANT_BE_TARGETED_BY_OPPONENTS = 270,
|
||||
NUM_TURNS_IN_PLAY = 271,
|
||||
NUM_TURNS_LEFT = 272,
|
||||
OUTGOING_DAMAGE_CAP = 273,
|
||||
OUTGOING_DAMAGE_ADJUSTMENT = 274,
|
||||
OUTGOING_DAMAGE_MULTIPLIER = 275,
|
||||
OUTGOING_HEALING_CAP = 276,
|
||||
OUTGOING_HEALING_ADJUSTMENT = 277,
|
||||
OUTGOING_HEALING_MULTIPLIER = 278,
|
||||
INCOMING_ABILITY_DAMAGE_ADJUSTMENT = 279,
|
||||
INCOMING_COMBAT_DAMAGE_ADJUSTMENT = 280,
|
||||
OUTGOING_ABILITY_DAMAGE_ADJUSTMENT = 281,
|
||||
OUTGOING_COMBAT_DAMAGE_ADJUSTMENT = 282,
|
||||
OUTGOING_ABILITY_DAMAGE_MULTIPLIER = 283,
|
||||
OUTGOING_ABILITY_DAMAGE_CAP = 284,
|
||||
INCOMING_ABILITY_DAMAGE_MULTIPLIER = 285,
|
||||
INCOMING_ABILITY_DAMAGE_CAP = 286,
|
||||
OUTGOING_COMBAT_DAMAGE_MULTIPLIER = 287,
|
||||
OUTGOING_COMBAT_DAMAGE_CAP = 288,
|
||||
INCOMING_COMBAT_DAMAGE_MULTIPLIER = 289,
|
||||
INCOMING_COMBAT_DAMAGE_CAP = 290,
|
||||
CURRENT_SPELLPOWER = 291,
|
||||
ARMOR = 292,
|
||||
MORPH = 293,
|
||||
IS_MORPHED = 294,
|
||||
TEMP_RESOURCES = 295,
|
||||
OVERLOAD_OWED = 296,
|
||||
NUM_ATTACKS_THIS_TURN = 297,
|
||||
NEXT_ALLY_BUFF = 302,
|
||||
MAGNET = 303,
|
||||
FIRST_CARD_PLAYED_THIS_TURN = 304,
|
||||
MULLIGAN_STATE = 305,
|
||||
TAUNT_READY = 306,
|
||||
STEALTH_READY = 307,
|
||||
CHARGE_READY = 308,
|
||||
CANT_BE_TARGETED_BY_ABILITIES = 311,
|
||||
SHOULDEXITCOMBAT = 312,
|
||||
CREATOR = 313,
|
||||
CANT_BE_DISPELLED = 314,
|
||||
PARENT_CARD = 316,
|
||||
NUM_MINIONS_PLAYED_THIS_TURN = 317,
|
||||
PREDAMAGE = 318,
|
||||
TARGETING_ARROW_TEXT = 325,
|
||||
ENCHANTMENT_BIRTH_VISUAL = 330,
|
||||
ENCHANTMENT_IDLE_VISUAL = 331,
|
||||
CANT_BE_TARGETED_BY_HERO_POWERS = 332,
|
||||
HEALTH_MINIMUM = 337,
|
||||
TAG_ONE_TURN_EFFECT = 338,
|
||||
SILENCE = 339,
|
||||
COUNTER = 340,
|
||||
ARTISTNAME = 342,
|
||||
HAND_REVEALED = 348,
|
||||
ADJACENT_BUFF = 350,
|
||||
FLAVORTEXT = 351,
|
||||
FORCED_PLAY = 352,
|
||||
LOW_HEALTH_THRESHOLD = 353,
|
||||
SPELLPOWER_DOUBLE = 356,
|
||||
HEALING_DOUBLE = 357,
|
||||
NUM_OPTIONS_PLAYED_THIS_TURN = 358,
|
||||
TO_BE_DESTROYED = 360,
|
||||
AURA = 362,
|
||||
POISONOUS = 363,
|
||||
HOW_TO_EARN = 364,
|
||||
HOW_TO_EARN_GOLDEN = 365,
|
||||
HERO_POWER_DOUBLE = 366,
|
||||
AI_MUST_PLAY = 367,
|
||||
NUM_MINIONS_PLAYER_KILLED_THIS_TURN = 368,
|
||||
NUM_MINIONS_KILLED_THIS_TURN = 369,
|
||||
AFFECTED_BY_SPELL_POWER = 370,
|
||||
EXTRA_DEATHRATTLES = 371,
|
||||
START_WITH_1_HEALTH = 372,
|
||||
IMMUNE_WHILE_ATTACKING = 373,
|
||||
MULTIPLY_HERO_DAMAGE = 374,
|
||||
MULTIPLY_BUFF_VALUE = 375,
|
||||
CUSTOM_KEYWORD_EFFECT = 376,
|
||||
TOPDECK = 377,
|
||||
CANT_BE_TARGETED_BY_BATTLECRIES = 379,
|
||||
SHOWN_HERO_POWER = 380,
|
||||
DEATHRATTLE_RETURN_ZONE = 382,
|
||||
STEADY_SHOT_CAN_TARGET = 383,
|
||||
DISPLAYED_CREATOR = 385,
|
||||
POWERED_UP = 386,
|
||||
SPARE_PART = 388,
|
||||
FORGETFUL = 389,
|
||||
CAN_SUMMON_MAXPLUSONE_MINION = 390,
|
||||
OBFUSCATED = 391,
|
||||
BURNING = 392,
|
||||
OVERLOAD_LOCKED = 393,
|
||||
NUM_TIMES_HERO_POWER_USED_THIS_GAME = 394,
|
||||
CURRENT_HEROPOWER_DAMAGE_BONUS = 395,
|
||||
HEROPOWER_DAMAGE = 396,
|
||||
LAST_CARD_PLAYED = 397,
|
||||
NUM_FRIENDLY_MINIONS_THAT_DIED_THIS_TURN = 398,
|
||||
NUM_CARDS_DRAWN_THIS_TURN = 399,
|
||||
AI_ONE_SHOT_KILL = 400,
|
||||
EVIL_GLOW = 401,
|
||||
HIDE_COST = 402,
|
||||
INSPIRE = 403,
|
||||
RECEIVES_DOUBLE_SPELLDAMAGE_BONUS = 404,
|
||||
HEROPOWER_ADDITIONAL_ACTIVATIONS = 405,
|
||||
HEROPOWER_ACTIVATIONS_THIS_TURN = 406,
|
||||
REVEALED = 410,
|
||||
NUM_FRIENDLY_MINIONS_THAT_DIED_THIS_GAME = 412,
|
||||
CANNOT_ATTACK_HEROES = 413,
|
||||
LOCK_AND_LOAD = 414,
|
||||
TREASURE = 415,
|
||||
SHADOWFORM = 416,
|
||||
NUM_FRIENDLY_MINIONS_THAT_ATTACKED_THIS_TURN = 417,
|
||||
NUM_RESOURCES_SPENT_THIS_GAME = 418,
|
||||
CHOOSE_BOTH = 419,
|
||||
ELECTRIC_CHARGE_LEVEL = 420,
|
||||
HEAVILY_ARMORED = 421,
|
||||
DONT_SHOW_IMMUNE = 422,
|
||||
HISTORY_PROXY_NO_BIG_CARD = 432,
|
||||
TRANSFORMED_FROM_CARD = 435,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef MISC_H_
|
||||
#define MISC_H_
|
||||
|
||||
struct gamesetup_s {
|
||||
u64 board;
|
||||
u64 maxsecrets;
|
||||
u64 maxfriendlyminions;
|
||||
u64 keepalive;
|
||||
u64 stuckdisconnect;
|
||||
};
|
||||
|
||||
struct handshake_s {
|
||||
u64 gamehandle;
|
||||
char *password;
|
||||
int npassword;
|
||||
u64 clienthandle;
|
||||
u64 mission;
|
||||
char *version;
|
||||
int nversion;
|
||||
|
||||
struct platform_s *platform;
|
||||
};
|
||||
|
||||
struct platform_s {
|
||||
u64 os;
|
||||
u64 screen;
|
||||
int nname;
|
||||
char *name;
|
||||
u64 store;
|
||||
};
|
||||
|
||||
struct chooseoption_s {
|
||||
u64 id;
|
||||
u64 index;
|
||||
u64 target;
|
||||
u64 suboption;
|
||||
u64 position;
|
||||
};
|
||||
|
||||
void gamesetup_free(struct gamesetup_s *g);
|
||||
int gamesetup_serialize(void *data, char **dst, const char *maxdst);
|
||||
void *gamesetup_deserialize(char **dst, const char *maxdst);
|
||||
|
||||
void handshake_free(struct handshake_s *h);
|
||||
void *handshake_deserialize(char **dst, const char *maxdst);
|
||||
int handshake_serialize(void *ao, char **dst, const char *maxdst);
|
||||
|
||||
void platform_free(struct platform_s *p);
|
||||
struct platform_s *platform_deserialize(char **dst, const char *maxdst);
|
||||
int platform_serialize(void *ao, char **dst, const char *maxdst);
|
||||
int platform_size(struct platform_s *p);
|
||||
|
||||
int chooseoption_serialize(void *ao, char **dst, const char *maxdst);
|
||||
void chooseoption_free(struct chooseoption_s *c);
|
||||
void *chooseoption_deserialize(char **dst, const char *maxdst);
|
||||
void chooseoption_dump(struct chooseoption_s *o, u64 local_held_card);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef MOUSEINFO_H_
|
||||
#define MOUSEINFO_H_
|
||||
|
||||
struct mouseinfo_s {
|
||||
u64 arroworigin;
|
||||
u64 heldcard;
|
||||
u64 overcard;
|
||||
u64 x;
|
||||
u64 y;
|
||||
};
|
||||
|
||||
void mouseinfo_free(struct mouseinfo_s *p);
|
||||
void *mouseinfo_deserialize(char **dst, const char *maxdst);
|
||||
int mouseinfo_serialize(void *ao, char **dst, const char *maxdst);
|
||||
int mouseinfo_size(struct mouseinfo_s *p);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef OPTIONS_H_
|
||||
#define OPTIONS_H_
|
||||
|
||||
struct suboption_target_s {
|
||||
u64 value;
|
||||
struct suboption_target_s *next;
|
||||
};
|
||||
|
||||
struct suboption_s {
|
||||
u64 id;
|
||||
struct suboption_target_s *target;
|
||||
|
||||
struct suboption_s *next;
|
||||
};
|
||||
|
||||
struct option_s {
|
||||
u64 type;
|
||||
struct suboption_s *mainoption;
|
||||
struct suboption_s *suboptions;
|
||||
|
||||
struct option_s *next;
|
||||
};
|
||||
|
||||
struct alloptions_s {
|
||||
u64 id;
|
||||
struct option_s *options;
|
||||
};
|
||||
|
||||
void alloptions_free(struct alloptions_s *a);
|
||||
int alloptions_serialize(void *s, char **dst, const char *maxdst);
|
||||
int alloptions_size(struct alloptions_s *p);
|
||||
|
||||
void option_free(struct option_s *p);
|
||||
int option_serialize(struct option_s *s, char **dst, const char *maxdst);
|
||||
int option_size(struct option_s *p);
|
||||
|
||||
void suboption_free(struct suboption_s *p);
|
||||
int suboption_serialize(struct suboption_s *s, char **dst, const char *maxdst);
|
||||
int suboption_size(struct suboption_s *p);
|
||||
|
||||
void alloptions_dump(struct alloptions_s *a);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PACKET_H_
|
||||
#define PACKET_H_
|
||||
|
||||
enum packet_e {
|
||||
P_GETGAMESTATE = 0x01,
|
||||
P_CHOOSEOPTION = 0x02,
|
||||
P_CHOOSEENTITIES = 0x03,
|
||||
P_TURNTIMER = 0x09,
|
||||
P_ENTITIESCHOSEN = 0x0D,
|
||||
P_ALLOPTIONS = 0x0E,
|
||||
P_USERUI = 0x0F,
|
||||
P_GAMESETUP = 0x10,
|
||||
P_ENTITYCHOICES = 0x11,
|
||||
P_POWERHISTORY = 0x13,
|
||||
P_SPECTATORNOTIFY = 0x18,
|
||||
P_PING = 0x73,
|
||||
P_PONG = 0x74,
|
||||
P_HANDSHAKE = 0xA8,
|
||||
};
|
||||
|
||||
struct packet_s {
|
||||
int id;
|
||||
int len;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct packet_meta_s {
|
||||
int id;
|
||||
void *(*deserialize)(char **dst, const char *end);
|
||||
int (*serialize)(void *p, char **dst, const char *end);
|
||||
int (*free)(void *p);
|
||||
};
|
||||
|
||||
#define parse_packet(m_p, m_buf, m_nbuf)\
|
||||
char *ptrd##m_buf = m_buf;\
|
||||
m_p = deserialize(&ptrd##m_buf, ptrd##m_buf + m_nbuf);
|
||||
|
||||
#define build_packet(m_p, m_src, m_type, m_buffer)\
|
||||
char m_buffer[8192];\
|
||||
char *ptr##m_buffer;\
|
||||
int n##m_buffer = 0;\
|
||||
ptr##m_buffer = m_buffer;\
|
||||
add_packet(&m_p, m_src, m_type);\
|
||||
n##m_buffer = serialize(m_p, &ptr##m_buffer, ptr##m_buffer + sizeof(m_buffer));
|
||||
|
||||
void packet_free(struct packet_s *p);
|
||||
struct packet_s *deserialize(char **dst, const char *maxdst);
|
||||
int serialize(struct packet_s *p, char **dst, const char *maxdst);
|
||||
struct packet_s *packet_init(enum packet_e id, void *data);
|
||||
void add_packet(struct packet_s **dst, void *ph, enum packet_e n);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef DEF_H_
|
||||
#define DEF_H_
|
||||
|
||||
struct powerhistory_tag_s {
|
||||
u64 name;
|
||||
u64 value;
|
||||
|
||||
struct powerhistory_tag_s *next;
|
||||
};
|
||||
|
||||
struct powerhistory_hide_s {
|
||||
u64 entity;
|
||||
u64 zone;
|
||||
};
|
||||
|
||||
struct powerhistory_tagchange_s {
|
||||
u64 entity;
|
||||
u64 tag;
|
||||
u64 value;
|
||||
};
|
||||
|
||||
struct powerhistory_entity_s {
|
||||
u64 entity;
|
||||
char *name;
|
||||
int nname;
|
||||
|
||||
struct powerhistory_tag_s *tag, *tag_tail;
|
||||
};
|
||||
|
||||
struct powerhistory_powerstart_s {
|
||||
u64 type;
|
||||
u64 index;
|
||||
u64 source;
|
||||
u64 target;
|
||||
|
||||
int ncard_id;
|
||||
char *card_id;
|
||||
};
|
||||
|
||||
struct powerhistory_powerend_s {
|
||||
int i;
|
||||
};
|
||||
|
||||
struct powerhistory_game_entity_s {
|
||||
u64 id;
|
||||
struct powerhistory_tag_s *tag, *tag_tail;
|
||||
};
|
||||
|
||||
struct powerhistory_s {
|
||||
struct powerhistory_data_s *data, *data_tail;
|
||||
};
|
||||
|
||||
struct powerhistory_info_s {
|
||||
u64 id;
|
||||
struct powerhistory_info_s *next;
|
||||
};
|
||||
|
||||
struct powerhistory_meta_s {
|
||||
u64 type;
|
||||
u64 data;
|
||||
struct powerhistory_info_s *info, *info_tail;
|
||||
};
|
||||
|
||||
struct powerhistory_player_s {
|
||||
u64 id;
|
||||
u64 bnet_hi;
|
||||
u64 bnet_lo;
|
||||
u64 cardback;
|
||||
struct powerhistory_game_entity_s *entity;
|
||||
|
||||
struct powerhistory_player_s *next;
|
||||
};
|
||||
|
||||
struct powerhistory_creategame_s {
|
||||
struct powerhistory_game_entity_s *game_entity;
|
||||
struct powerhistory_player_s *player, *player_tail;
|
||||
};
|
||||
|
||||
struct powerhistory_data_s {
|
||||
struct powerhistory_entity_s *full;
|
||||
struct powerhistory_entity_s *show;
|
||||
struct powerhistory_hide_s *hide;
|
||||
struct powerhistory_tagchange_s *tagchange;
|
||||
struct powerhistory_creategame_s *creategame;
|
||||
struct powerhistory_powerstart_s *powerstart;
|
||||
struct powerhistory_powerend_s *powerend;
|
||||
struct powerhistory_entity_s *change_entity;
|
||||
struct powerhistory_meta_s *meta;
|
||||
|
||||
struct powerhistory_data_s *next, *tail;
|
||||
};
|
||||
|
||||
void powerhistory_free(struct powerhistory_s *p);
|
||||
void *powerhistory_deserialize(char **dst, const char *maxdst);
|
||||
int powerhistory_serialize(void *data, char **dst, const char *maxdst);
|
||||
int powerhistory_size(struct powerhistory_s *ph);
|
||||
|
||||
struct powerhistory_data_s *powerhistory_data_deserialize(char **dst, const char *maxdst);
|
||||
int powerhistorydata_serialize(struct powerhistory_data_s *ph, char **dst, const char *maxdst);
|
||||
int powerhistorydata_size(struct powerhistory_data_s *ph);
|
||||
void powerhistory_data_free(struct powerhistory_data_s *d);
|
||||
|
||||
struct powerhistory_meta_s *meta_deserialize(char **dst, const char *maxdst);
|
||||
int meta_serialize(struct powerhistory_meta_s *ph, char **dst, const char *maxdst);
|
||||
int meta_size(struct powerhistory_meta_s *ph);
|
||||
void meta_free(struct powerhistory_meta_s *t);
|
||||
|
||||
struct powerhistory_powerend_s *powerend_deserialize(char **dst, const char *maxdst);
|
||||
int powerend_serialize(struct powerhistory_powerend_s *ph, char **dst, const char *maxdst);
|
||||
int powerend_size(struct powerhistory_powerend_s *ph);
|
||||
void powerend_free(struct powerhistory_powerend_s *p);
|
||||
|
||||
struct powerhistory_powerstart_s *powerstart_deserialize(char **dst, const char *maxdst);
|
||||
int powerstart_serialize(struct powerhistory_powerstart_s *ph, char **dst, const char *maxdst);
|
||||
int powerstart_size(struct powerhistory_powerstart_s *ph);
|
||||
void powerstart_free(struct powerhistory_powerstart_s *p);
|
||||
|
||||
struct powerhistory_creategame_s *creategame_deserialize(char **dst, const char *maxdst);
|
||||
int creategame_serialize(struct powerhistory_creategame_s *ph, char **dst, const char *maxdst);
|
||||
int creategame_size(struct powerhistory_creategame_s *ph);
|
||||
void creategame_free(struct powerhistory_creategame_s *c);
|
||||
|
||||
struct powerhistory_tagchange_s *tagchange_deserialize(char **dst, const char *maxdst);
|
||||
int tagchange_serialize(struct powerhistory_tagchange_s *ph, char **dst, const char *maxdst);
|
||||
int tagchange_size(struct powerhistory_tagchange_s *ph);
|
||||
void tagchange_free(struct powerhistory_tagchange_s *t);
|
||||
|
||||
struct powerhistory_hide_s *hide_deserialize(char **dst, const char *maxdst);
|
||||
int hide_serialize(struct powerhistory_hide_s *ph, char **dst, const char *maxdst);
|
||||
int hide_size(struct powerhistory_hide_s *ph);
|
||||
void hide_free(struct powerhistory_hide_s *t);
|
||||
|
||||
struct powerhistory_game_entity_s *game_entity_deserialize(char **dst, const char *maxdst);
|
||||
int game_entity_serialize(struct powerhistory_game_entity_s *ph, char **dst, const char *maxdst);
|
||||
int game_entity_size(struct powerhistory_game_entity_s *ph);
|
||||
void game_entity_free(struct powerhistory_game_entity_s *g);
|
||||
|
||||
struct powerhistory_entity_s *entity_deserialize(char **dst, const char *maxdst);
|
||||
int entity_serialize(struct powerhistory_entity_s *ph, char **dst, const char *maxdst);
|
||||
int entity_size(struct powerhistory_entity_s *ph);
|
||||
void entity_free(struct powerhistory_entity_s *e);
|
||||
|
||||
struct powerhistory_tag_s *tag_deserialize(char **dst, const char *maxdst);
|
||||
int tag_serialize(struct powerhistory_tag_s *ph, char **dst, const char *maxdst);
|
||||
int tag_size(struct powerhistory_tag_s *ph);
|
||||
void tag_free(struct powerhistory_tag_s *t);
|
||||
|
||||
void player_free(struct powerhistory_player_s *p);
|
||||
struct powerhistory_player_s *player_deserialize(char **dst, const char *maxdst);
|
||||
int player_serialize(struct powerhistory_player_s *ph, char **dst, const char *maxdst);
|
||||
int player_size(struct powerhistory_player_s *ph);
|
||||
|
||||
int bnet_size(struct powerhistory_player_s *ph);
|
||||
|
||||
void powerhistory_dump(struct powerhistory_s *p);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PROTO_H_
|
||||
#define PROTO_H_
|
||||
|
||||
#define error()\
|
||||
hm_log(LOG_EMERG, lg, "dst: %p end: %p n: %d", *dst, maxdst, n);\
|
||||
abort();
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <ev.h>
|
||||
|
||||
#include <hmbase.h>
|
||||
|
||||
typedef unsigned long long u64;
|
||||
|
||||
#include <zone.h>
|
||||
#include <misc.h>
|
||||
#include <powerhistory.h>
|
||||
#include <packet.h>
|
||||
#include <gametag.h>
|
||||
#include <entitychoices.h>
|
||||
#include <chooseentities.h>
|
||||
#include <options.h>
|
||||
#include <mouseinfo.h>
|
||||
#include <userui.h>
|
||||
#include <turntimer.h>
|
||||
|
||||
int sizeofu64(u64 v);
|
||||
int sizeofu32(int v);
|
||||
int write_byte(char **dst, const char *end, const char src);
|
||||
int write_bytes(char **dst, const char *end, const char *src, const int nsrc);
|
||||
void write_uint(char **dst, const char *end, int src);
|
||||
void write_uint64(char **dst, const char *end, u64 src);
|
||||
int write_mem_int(char **dst, const char *end, const int src);
|
||||
char read_byte(char **dst, const char *end);
|
||||
int read_uint(char **dst, const char *end);
|
||||
u64 read_uint64(char **dst, const char *end);
|
||||
int read_mem_int(char **dst, const char *end);
|
||||
char *read_bytes(char **dst, const char *end, int *ndst);
|
||||
int skip(char **dst, const char *end, const int jump);
|
||||
|
||||
extern struct hm_log_s *lg;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TURNTIMER_H_
|
||||
#define TURNTIMER_H_
|
||||
|
||||
struct turntimer_s {
|
||||
u64 seconds;
|
||||
u64 turn;
|
||||
char show;
|
||||
};
|
||||
|
||||
void turntimer_free(struct turntimer_s *t);
|
||||
int turntimer_serialize(void *ao, char **dst, const char *maxdst);
|
||||
void turntimer_dump(struct turntimer_s *t);
|
||||
void *turntimer_deserialize(char **dst, const char *maxdst);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef USERUI_H_
|
||||
#define USERUI_H_
|
||||
|
||||
struct userui_s {
|
||||
struct mouseinfo_s *mouseinfo;
|
||||
u64 emote;
|
||||
u64 player_id;
|
||||
};
|
||||
|
||||
void userui_free(struct userui_s *u);
|
||||
int userui_serialize(void *ao, char **dst, const char *maxdst);
|
||||
void *userui_deserialize(char **dst, const char *maxdst);
|
||||
int userui_size(struct userui_s *p);
|
||||
void userui_dump(struct userui_s *u);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef ZONE_H_
|
||||
#define ZONE_H_
|
||||
|
||||
enum zone_e {
|
||||
ZONE_INVALID = 0,
|
||||
ZONE_PLAY = 1,
|
||||
ZONE_DECK = 2,
|
||||
ZONE_HAND = 3,
|
||||
ZONE_GRAVEYARD = 4,
|
||||
ZONE_REMOVEDFROMGAME = 5,
|
||||
ZONE_SETASIDE = 6,
|
||||
ZONE_SECRET = 7,
|
||||
ZONE_DISCARD = -2,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void meta_free(struct powerhistory_meta_s *t)
|
||||
{
|
||||
struct powerhistory_info_s *info, *del;
|
||||
|
||||
for(info = t->info; info != NULL; del = info, info = info->next, free(del));
|
||||
|
||||
free(t);
|
||||
}
|
||||
|
||||
struct powerhistory_meta_s *meta_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct powerhistory_meta_s *t;
|
||||
struct powerhistory_info_s *info;
|
||||
int i;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
memset(t, 0, sizeof(*t));
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 18) {
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
info = malloc(sizeof(*info));
|
||||
info->id = read_uint64(dst, maxdst);
|
||||
info->next = NULL;
|
||||
|
||||
if(t->info == NULL && t->info_tail == NULL) {
|
||||
t->info = info;
|
||||
t->info_tail = info;
|
||||
} else {
|
||||
t->info_tail->next = info;
|
||||
t->info_tail = info;
|
||||
}
|
||||
}
|
||||
} else if(n == 24) {
|
||||
t->type = read_uint64(dst, maxdst);
|
||||
} else if(n == 32) {
|
||||
t->data = read_uint64(dst, maxdst);
|
||||
} else {
|
||||
error();
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
int meta_size(struct powerhistory_meta_s *p)
|
||||
{
|
||||
int num = 0, num2;
|
||||
struct powerhistory_info_s *m;
|
||||
|
||||
if(p->info) {
|
||||
num += 1;
|
||||
num2 = num;
|
||||
for(m = p->info; m != NULL; m = m->next) {
|
||||
num += sizeofu64(m->id);
|
||||
}
|
||||
num += sizeofu32(num - num2);
|
||||
}
|
||||
|
||||
if(p->type != 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(p->type);
|
||||
}
|
||||
|
||||
if(p->data != 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(p->data);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int meta_serialize(struct powerhistory_meta_s *p, char **dst, const char *maxdst)
|
||||
{
|
||||
int num = 0;
|
||||
struct powerhistory_info_s *m;
|
||||
|
||||
if(p->info) {
|
||||
write_byte(dst, maxdst, 18);
|
||||
for(m = p->info; m != NULL; m = m->next) {
|
||||
num += sizeofu64(m->id);
|
||||
}
|
||||
|
||||
write_uint(dst, maxdst, num);
|
||||
|
||||
for(m = p->info; m != NULL; m = m->next) {
|
||||
write_uint64(dst, maxdst, m->id);
|
||||
}
|
||||
}
|
||||
|
||||
if(p->type != 0) {
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, p->type);
|
||||
}
|
||||
|
||||
if(p->data != 0) {
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, p->data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void mouseinfo_free(struct mouseinfo_s *m)
|
||||
{
|
||||
free(m);
|
||||
}
|
||||
|
||||
void *mouseinfo_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct mouseinfo_s *c;
|
||||
|
||||
c = malloc(sizeof(*c));
|
||||
memset(c, 0, sizeof(*c));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
c->arroworigin = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
c->heldcard = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
c->overcard = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 32) {
|
||||
error();
|
||||
}
|
||||
c->x = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 40) {
|
||||
error();
|
||||
}
|
||||
c->y = read_uint64(dst, maxdst);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int mouseinfo_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct mouseinfo_s *s;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->arroworigin);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, s->heldcard);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, s->overcard);
|
||||
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, s->x);
|
||||
|
||||
write_byte(dst, maxdst, 40);
|
||||
write_uint64(dst, maxdst, s->y);
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
int mouseinfo_size(struct mouseinfo_s *p)
|
||||
{
|
||||
int num = 0;
|
||||
|
||||
num += 5;
|
||||
num += sizeofu64(p->arroworigin);
|
||||
num += sizeofu64(p->heldcard);
|
||||
num += sizeofu64(p->overcard);
|
||||
num += sizeofu64(p->x);
|
||||
num += sizeofu64(p->y);
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void option_free(struct option_s *o)
|
||||
{
|
||||
struct suboption_s *s, *del;
|
||||
|
||||
for(s = o->mainoption; s != NULL; del = s, s = s->next, suboption_free(del));
|
||||
|
||||
for(s = o->suboptions; s != NULL; del = s, s = s->next, suboption_free(del));
|
||||
|
||||
free(o);
|
||||
}
|
||||
|
||||
int option_serialize(struct option_s *s, char **dst, const char *maxdst)
|
||||
{
|
||||
int n = 0;
|
||||
struct suboption_s *m;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->type);
|
||||
|
||||
if(s->mainoption) {
|
||||
write_byte(dst, maxdst, 18);
|
||||
n = suboption_size(s->mainoption);
|
||||
write_uint(dst, maxdst, n);
|
||||
suboption_serialize(s->mainoption, dst, maxdst);
|
||||
}
|
||||
|
||||
if(s->suboptions) {
|
||||
for(m = s->suboptions; m != NULL; m = m->next) {
|
||||
write_byte(dst, maxdst, 26);
|
||||
n = suboption_size(m);
|
||||
write_uint(dst, maxdst, n);
|
||||
suboption_serialize(m, dst, maxdst);
|
||||
}
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
int option_size(struct option_s *p)
|
||||
{
|
||||
int num = 0, n;
|
||||
struct suboption_s *s;
|
||||
|
||||
num += 1;
|
||||
num += sizeofu64(p->type);
|
||||
|
||||
if(p->mainoption) {
|
||||
num += 1;
|
||||
n = suboption_size(p->mainoption);
|
||||
num += sizeofu32(n) + n;
|
||||
}
|
||||
|
||||
if(p->suboptions) {
|
||||
for(s = p->suboptions; s != NULL; s = s->next) {
|
||||
num += 1;
|
||||
n = suboption_size(s);
|
||||
num += sizeofu32(n) + n;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
#define MAP_PACKET_MAX 12
|
||||
|
||||
typedef int (*f)(void *c);
|
||||
|
||||
static struct packet_meta_s map_packet[MAP_PACKET_MAX] = {
|
||||
{P_GETGAMESTATE, NULL, NULL, NULL},
|
||||
{P_CHOOSEOPTION, chooseoption_deserialize, chooseoption_serialize, (f)chooseoption_free},
|
||||
{P_TURNTIMER, turntimer_deserialize, turntimer_serialize, (f)turntimer_free},
|
||||
{P_CHOOSEENTITIES, chooseentities_deserialize, chooseentities_serialize, (f)chooseentities_free},
|
||||
{P_ALLOPTIONS, NULL, alloptions_serialize, (f)alloptions_free},
|
||||
{P_ENTITYCHOICES, entitychoices_deserialize, entitychoices_serialize, (f)entitychoices_free},
|
||||
{P_GAMESETUP, gamesetup_deserialize, gamesetup_serialize, (f)gamesetup_free},
|
||||
{P_USERUI, userui_deserialize, userui_serialize, (f)userui_free},
|
||||
{P_POWERHISTORY, powerhistory_deserialize, powerhistory_serialize, (f)powerhistory_free},
|
||||
{P_HANDSHAKE, handshake_deserialize, handshake_serialize, (f)handshake_free},
|
||||
{P_PING, NULL, NULL, NULL},
|
||||
{P_PONG, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
struct packet_s *deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
struct packet_s *p;
|
||||
int i;
|
||||
|
||||
if(!(dst != NULL && *dst != NULL && *dst < maxdst)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = malloc(sizeof(*p));
|
||||
|
||||
p->id = read_mem_int(dst, maxdst);
|
||||
p->len = read_mem_int(dst, maxdst);
|
||||
|
||||
for(i = 0; i < MAP_PACKET_MAX; i++) {
|
||||
if(map_packet[i].id == p->id) {
|
||||
if(map_packet[i].deserialize) {
|
||||
p->data = map_packet[i].deserialize(dst, maxdst);
|
||||
assert(p->data);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
free(p);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void packet_free(struct packet_s *p)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < MAP_PACKET_MAX; i++) {
|
||||
if(map_packet[i].id == p->id) {
|
||||
if(map_packet[i].free) {
|
||||
map_packet[i].free(p->data);
|
||||
}
|
||||
|
||||
free(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int serialize(struct packet_s *p, char **dst, const char *maxdst)
|
||||
{
|
||||
int i, n = 0;
|
||||
char *off_len;
|
||||
|
||||
write_mem_int(dst, maxdst, p->id);
|
||||
off_len = *dst;
|
||||
write_mem_int(dst, maxdst, 0); // make space for length
|
||||
|
||||
n += 2 * sizeof(int);
|
||||
|
||||
for(i = 0; i < MAP_PACKET_MAX; i++) {
|
||||
if(map_packet[i].id == p->id) {
|
||||
if(map_packet[i].serialize) {
|
||||
n += map_packet[i].serialize(p->data, dst, maxdst);
|
||||
}
|
||||
|
||||
write_mem_int(&off_len, maxdst, n - (2 * sizeof(int)));
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct packet_s *packet_init(enum packet_e id, void *data)
|
||||
{
|
||||
struct packet_s *p;
|
||||
|
||||
p = malloc(sizeof(*p));
|
||||
|
||||
p->id = id;
|
||||
p->data = data;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void add_packet(struct packet_s **dst, void *ph, enum packet_e n)
|
||||
{
|
||||
*dst = malloc(sizeof(**dst));
|
||||
memset(*dst, 0, sizeof(**dst));
|
||||
|
||||
(*dst)->data = ph;
|
||||
(*dst)->id = n;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void platform_free(struct platform_s *p)
|
||||
{
|
||||
free(p->name);
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
int platform_size(struct platform_s *p)
|
||||
{
|
||||
int num = 0;
|
||||
|
||||
num += 2;
|
||||
num += sizeofu64(p->os);
|
||||
num += sizeofu64(p->screen);
|
||||
|
||||
num += 1;
|
||||
num += sizeofu32(p->nname) + p->nname;
|
||||
|
||||
if(p->store != 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(p->store);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int platform_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct platform_s *s;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->os);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, s->screen);
|
||||
|
||||
write_byte(dst, maxdst, 26);
|
||||
write_bytes(dst, maxdst, s->name, s->nname);
|
||||
|
||||
if(s->store != 0) {
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, s->store);
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
struct platform_s *platform_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct platform_s *h;
|
||||
|
||||
h = malloc(sizeof(*h));
|
||||
h->store = 0;
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
h->os = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
h->screen = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 26) {
|
||||
error();
|
||||
}
|
||||
h->name = read_bytes(dst, maxdst, &h->nname);
|
||||
|
||||
if(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 32) {
|
||||
h->store = read_uint64(dst, maxdst);
|
||||
}
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void player_free(struct powerhistory_player_s *p)
|
||||
{
|
||||
game_entity_free(p->entity);
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
struct powerhistory_player_s *player_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct powerhistory_player_s *player;
|
||||
|
||||
player = malloc(sizeof(*player));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
player->id = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 18) {
|
||||
error();
|
||||
}
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
player->bnet_hi = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
player->bnet_lo = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
player->cardback = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 34) {
|
||||
error();
|
||||
}
|
||||
len = read_uint(dst, maxdst);
|
||||
player->entity = game_entity_deserialize(dst, *dst + len);
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
int player_serialize(struct powerhistory_player_s *player, char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, player->id);
|
||||
|
||||
// bnet
|
||||
write_byte(dst, maxdst, 18);
|
||||
n = bnet_size(player);
|
||||
write_uint(dst, maxdst, n);
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, player->bnet_hi);
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, player->bnet_lo);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, player->cardback);
|
||||
|
||||
write_byte(dst, maxdst, 34);
|
||||
n = game_entity_size(player->entity);
|
||||
write_uint(dst, maxdst, n);
|
||||
game_entity_serialize(player->entity, dst, maxdst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int player_size(struct powerhistory_player_s *p)
|
||||
{
|
||||
int size = 0, ts;
|
||||
|
||||
if(p) {
|
||||
size += 4;
|
||||
size += sizeofu64(p->id);
|
||||
ts = bnet_size(p);
|
||||
size += sizeofu32(ts) + ts;
|
||||
size += sizeofu64(p->cardback);
|
||||
ts = game_entity_size(p->entity);
|
||||
size += sizeofu32(ts) + ts;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void powerend_free(struct powerhistory_powerend_s *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
struct powerhistory_powerend_s *powerend_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
struct powerhistory_powerend_s *t;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int powerend_serialize(struct powerhistory_powerend_s *t, char **dst, const char *maxdst)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int powerend_size(struct powerhistory_powerend_s *p)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void powerhistory_free(struct powerhistory_s *p)
|
||||
{
|
||||
struct powerhistory_data_s *d, *del;
|
||||
|
||||
for(d = p->data; d != NULL; del = d, d = d->next, powerhistory_data_free(del));
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
void *powerhistory_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
struct powerhistory_s *p;
|
||||
struct powerhistory_data_s *d;
|
||||
int n, len;
|
||||
|
||||
p = malloc(sizeof(*p));
|
||||
p->data = NULL;
|
||||
p->data_tail = NULL;
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
if(n == 10) {
|
||||
d = powerhistory_data_deserialize(dst, *dst + len);
|
||||
d->next = NULL;
|
||||
|
||||
if(p->data == NULL && p->data_tail == NULL) {
|
||||
p->data = d;
|
||||
p->data_tail = d;
|
||||
} else {
|
||||
p->data_tail->next = d;
|
||||
p->data_tail = d;
|
||||
}
|
||||
|
||||
} else {
|
||||
error();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int powerhistory_serialize(void *data, char **dst, const char *maxdst)
|
||||
{
|
||||
int n, o = 0;
|
||||
struct powerhistory_data_s *d;
|
||||
struct powerhistory_s *ph = data;
|
||||
|
||||
if(ph->data) {
|
||||
for(d = ph->data; d != NULL; d = d->next) {
|
||||
write_byte(dst, maxdst, 10);
|
||||
o += 1;
|
||||
n = powerhistorydata_size(d);
|
||||
write_uint(dst, maxdst, n);
|
||||
o += sizeofu32(n) + n;
|
||||
powerhistorydata_serialize(d, dst, maxdst);
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
int powerhistory_size(struct powerhistory_s *ph)
|
||||
{
|
||||
struct powerhistory_data_s *d;
|
||||
int n, num = 0;
|
||||
|
||||
if(ph->data) {
|
||||
for(d = ph->data; d != NULL; d = d->next) {
|
||||
num += 1;
|
||||
n = powerhistorydata_size(d);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
void powerhistory_dump(struct powerhistory_s *p)
|
||||
{
|
||||
struct powerhistory_tag_s *t;
|
||||
struct powerhistory_data_s *d;
|
||||
struct powerhistory_game_entity_s *ge;
|
||||
struct powerhistory_player_s *player;
|
||||
struct powerhistory_info_s *i;
|
||||
int it = 0;
|
||||
|
||||
assert(p);
|
||||
|
||||
for(d = p->data; d != NULL; d = d->next) {
|
||||
hm_log(LOG_DEBUG, lg, "Data %d", it++);
|
||||
|
||||
if(d->full) {
|
||||
hm_log(LOG_DEBUG, lg, "data->full:");
|
||||
hm_log(LOG_DEBUG, lg, "\tentity: %lld name: [%.*s]", d->full->entity, d->full->nname, d->full->name);
|
||||
for(t = d->full->tag; t != NULL; t = t->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\ttag name: %lld value: %lld", t->name, t->value);
|
||||
}
|
||||
}
|
||||
|
||||
if(d->show) {
|
||||
hm_log(LOG_DEBUG, lg, "data->show:");
|
||||
hm_log(LOG_DEBUG, lg, "\tentity: %lld name: [%.*s]", d->show->entity, d->show->nname, d->show->name);
|
||||
for(t = d->show->tag; t != NULL; t = t->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\ttag name: %lld value: %lld", t->name, t->value);
|
||||
}
|
||||
}
|
||||
|
||||
if(d->hide) {
|
||||
hm_log(LOG_DEBUG, lg, "data->hide:");
|
||||
hm_log(LOG_DEBUG, lg, "\tentity: %lld zone: %lld", d->hide->entity, d->hide->zone);
|
||||
}
|
||||
|
||||
if(d->tagchange) {
|
||||
hm_log(LOG_DEBUG, lg, "data->tagchange:");
|
||||
hm_log(LOG_DEBUG, lg, "\tentity: %lld tag: %lld value: %lld", d->tagchange->entity, d->tagchange->tag, d->tagchange->value);
|
||||
}
|
||||
|
||||
if(d->creategame) {
|
||||
ge = d->creategame->game_entity;
|
||||
hm_log(LOG_DEBUG, lg, "game entity id: %lld", ge->id);
|
||||
for(t = ge->tag; t != NULL; t = t->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\ttag name: %lld value: %lld", t->name, t->value);
|
||||
}
|
||||
|
||||
for(player = d->creategame->player; player != NULL; player = player->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\tdata->creategame->player:");
|
||||
hm_log(LOG_DEBUG, lg, "\t\t\tid: %lld bhi: %lld blo: %lld cardback: %lld", player->id, player->bnet_hi, player->bnet_lo, player->cardback);
|
||||
ge = player->entity;
|
||||
hm_log(LOG_DEBUG, lg, "\t\t\tplayer->entity: %lld", ge->id);
|
||||
for(t = ge->tag; t != NULL; t = t->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\t\t\ttag name: %lld value: %lld", t->name, t->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(d->powerstart) {
|
||||
hm_log(LOG_DEBUG, lg, "data->powerstart");
|
||||
hm_log(LOG_DEBUG, lg, "\ttype: %lld index: %lld source: %lld target: %lld card: [%.*s]", d->powerstart->type, d->powerstart->index, d->powerstart->source, d->powerstart->target, d->powerstart->ncard_id, d->powerstart->card_id);
|
||||
}
|
||||
|
||||
if(d->powerend) {
|
||||
hm_log(LOG_DEBUG, lg, "data->powerend");
|
||||
}
|
||||
|
||||
if(d->change_entity) {
|
||||
hm_log(LOG_DEBUG, lg, "data->change_entity:");
|
||||
hm_log(LOG_DEBUG, lg, "\tentity: %lld name: [%.*s]", d->change_entity->entity, d->change_entity->nname, d->change_entity->name);
|
||||
for(t = d->change_entity->tag; t != NULL; t = t->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\ttag name: %lld value: %lld", t->name, t->value);
|
||||
}
|
||||
}
|
||||
|
||||
if(d->meta) {
|
||||
hm_log(LOG_DEBUG, lg, "data->meta:");
|
||||
hm_log(LOG_DEBUG, lg, "\ttype: %lld data: %lld", d->meta->type, d->meta->data);
|
||||
for(i = d->meta->info; i != NULL; i = i->next) {
|
||||
hm_log(LOG_DEBUG, lg, "\t\t\tinfo id: %lld", i->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void powerhistory_data_free(struct powerhistory_data_s *d)
|
||||
{
|
||||
if(d->full) entity_free(d->full);
|
||||
if(d->show) entity_free(d->show);
|
||||
if(d->hide) hide_free(d->hide);
|
||||
if(d->tagchange) tagchange_free(d->tagchange);
|
||||
if(d->creategame) creategame_free(d->creategame);
|
||||
if(d->powerstart) powerstart_free(d->powerstart);
|
||||
if(d->powerend) powerend_free(d->powerend);
|
||||
if(d->change_entity) entity_free(d->change_entity);
|
||||
if(d->meta) meta_free(d->meta);
|
||||
|
||||
free(d);
|
||||
}
|
||||
|
||||
struct powerhistory_data_s *powerhistory_data_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
struct powerhistory_data_s *p;
|
||||
int n, len;
|
||||
|
||||
p = malloc(sizeof(*p));
|
||||
memset(p, 0, sizeof(*p));
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
len = read_uint(dst, maxdst);
|
||||
|
||||
if(n == 10) {
|
||||
p->full = entity_deserialize(dst, *dst + len);
|
||||
} else if(n == 18) {
|
||||
p->show = entity_deserialize(dst, *dst + len);
|
||||
} else if(n == 26) {
|
||||
p->hide = hide_deserialize(dst, *dst + len);
|
||||
} else if(n == 34) {
|
||||
p->tagchange = tagchange_deserialize(dst, *dst + len);
|
||||
} else if(n == 42) {
|
||||
p->creategame = creategame_deserialize(dst, *dst + len);
|
||||
} else if(n == 50) {
|
||||
p->powerstart = powerstart_deserialize(dst, *dst + len);
|
||||
} else if(n == 58) {
|
||||
p->powerend = powerend_deserialize(dst, *dst + len);
|
||||
} else if(n == 66) {
|
||||
p->meta = meta_deserialize(dst, *dst + len);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int powerhistorydata_serialize(struct powerhistory_data_s *phd, char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
|
||||
if(phd->full) {
|
||||
write_byte(dst, maxdst, 10);
|
||||
n = entity_size(phd->full);
|
||||
write_uint(dst, maxdst, n);
|
||||
entity_serialize(phd->full, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->show) {
|
||||
write_byte(dst, maxdst, 18);
|
||||
n = entity_size(phd->show);
|
||||
write_uint(dst, maxdst, n);
|
||||
entity_serialize(phd->show, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->hide) {
|
||||
write_byte(dst, maxdst, 26);
|
||||
n = hide_size(phd->hide);
|
||||
write_uint(dst, maxdst, n);
|
||||
hide_serialize(phd->hide, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->tagchange) {
|
||||
write_byte(dst, maxdst, 34);
|
||||
n = tagchange_size(phd->tagchange);
|
||||
write_uint(dst, maxdst, n);
|
||||
tagchange_serialize(phd->tagchange, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->creategame) {
|
||||
write_byte(dst, maxdst, 42);
|
||||
n = creategame_size(phd->creategame);
|
||||
write_uint(dst, maxdst, n);
|
||||
creategame_serialize(phd->creategame, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->powerstart) {
|
||||
write_byte(dst, maxdst, 50);
|
||||
n = powerstart_size(phd->powerstart);
|
||||
write_uint(dst, maxdst, n);
|
||||
powerstart_serialize(phd->powerstart, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->powerend) {
|
||||
write_byte(dst, maxdst, 58);
|
||||
n = powerend_size(phd->powerend);
|
||||
write_uint(dst, maxdst, n);
|
||||
powerend_serialize(phd->powerend, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->meta) {
|
||||
write_byte(dst, maxdst, 66);
|
||||
n = meta_size(phd->meta);
|
||||
write_uint(dst, maxdst, n);
|
||||
meta_serialize(phd->meta, dst, maxdst);
|
||||
}
|
||||
|
||||
if(phd->change_entity) {
|
||||
write_byte(dst, maxdst, 74);
|
||||
n = entity_size(phd->change_entity);
|
||||
write_uint(dst, maxdst, n);
|
||||
entity_serialize(phd->change_entity, dst, maxdst);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int powerhistorydata_size(struct powerhistory_data_s *phd)
|
||||
{
|
||||
int num = 0, n;
|
||||
|
||||
if(phd->full) {
|
||||
num += 1;
|
||||
n = entity_size(phd->full);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->show) {
|
||||
num += 1;
|
||||
n = entity_size(phd->show);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->hide) {
|
||||
num += 1;
|
||||
n = hide_size(phd->hide);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->tagchange) {
|
||||
num += 1;
|
||||
n = tagchange_size(phd->tagchange);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->creategame) {
|
||||
num += 1;
|
||||
n = creategame_size(phd->creategame);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->powerstart) {
|
||||
num += 1;
|
||||
n = powerstart_size(phd->powerstart);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->powerend) {
|
||||
num += 1;
|
||||
n = powerend_size(phd->powerend);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->meta) {
|
||||
num += 1;
|
||||
n = meta_size(phd->meta);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(phd->change_entity) {
|
||||
num += 1;
|
||||
n = entity_size(phd->change_entity);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void powerstart_free(struct powerhistory_powerstart_s *p)
|
||||
{
|
||||
free(p->card_id);
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
struct powerhistory_powerstart_s *powerstart_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct powerhistory_powerstart_s *t;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
t->type = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
t->index = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
t->source = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 32) {
|
||||
error();
|
||||
}
|
||||
t->target = read_uint64(dst, maxdst);
|
||||
|
||||
t->ncard_id = 0;
|
||||
t->card_id = NULL;
|
||||
// optional
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 42) {
|
||||
return t;
|
||||
}
|
||||
|
||||
t->card_id = read_bytes(dst, maxdst, &t->ncard_id);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int powerstart_serialize(struct powerhistory_powerstart_s *p, char **dst, const char *maxdst)
|
||||
{
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, p->type);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, p->index);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, p->source);
|
||||
|
||||
write_byte(dst, maxdst, 32);
|
||||
write_uint64(dst, maxdst, p->target);
|
||||
|
||||
if(p->ncard_id > 0) {
|
||||
write_byte(dst, maxdst, 42);
|
||||
write_bytes(dst, maxdst, p->card_id, p->ncard_id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int powerstart_size(struct powerhistory_powerstart_s *p)
|
||||
{
|
||||
int size = 0;
|
||||
int n;
|
||||
|
||||
if(p) {
|
||||
size += 4;
|
||||
size += sizeofu64(p->type);
|
||||
size += sizeofu64(p->index);
|
||||
size += sizeofu64(p->source);
|
||||
size += sizeofu64(p->target);
|
||||
if(p->ncard_id > 0) {
|
||||
size += 1;
|
||||
n = sizeofu64(p->ncard_id);
|
||||
size += sizeofu32(n) + n;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
int sizeofu64(u64 val)
|
||||
{
|
||||
unsigned int num = 1u;
|
||||
|
||||
while(1 == 1) {
|
||||
val >>= 7;
|
||||
if(val == 0) {
|
||||
break;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int sizeofu32(int val)
|
||||
{
|
||||
unsigned int num = 1u;
|
||||
|
||||
while(1 == 1) {
|
||||
val >>= 7;
|
||||
if(val == 0) {
|
||||
break;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int read_mem_int(char **dst, const char *end)
|
||||
{
|
||||
int n;
|
||||
|
||||
if(*dst + sizeof(int) > end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = *(int *)(*dst);
|
||||
(*dst) += sizeof(int);
|
||||
return n;
|
||||
}
|
||||
|
||||
int write_mem_int(char **dst, const char *end, const int src)
|
||||
{
|
||||
if(*dst + sizeof(src) > end) {
|
||||
hm_log(LOG_EMERG, lg, "Cannot write %d %p %p", src, *dst, end);
|
||||
abort();
|
||||
}
|
||||
|
||||
memcpy(*dst, &src, sizeof(src));
|
||||
(*dst) += sizeof(src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int write_byte(char **dst, const char *end, char src)
|
||||
{
|
||||
if(*dst + sizeof(src) > end) {
|
||||
hm_log(LOG_EMERG, lg, "Cannot write %d %p %p", src, *dst, end);
|
||||
abort();
|
||||
}
|
||||
|
||||
memcpy(*dst, &src, sizeof(src));
|
||||
(*dst)++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char read_byte(char **dst, const char *end)
|
||||
{
|
||||
char out;
|
||||
|
||||
if(*dst + sizeof(char) > end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
out = *((char *)(*dst));
|
||||
|
||||
(*dst)++;
|
||||
return out;
|
||||
}
|
||||
|
||||
int skip(char **dst, const char *end, const int jump)
|
||||
{
|
||||
if((*dst + jump) > end) {
|
||||
hm_log(LOG_ALERT, lg, "Invalid skip %p %p %d", *dst, end, jump);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*dst += jump;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_uint(char **dst, const char *end)
|
||||
{
|
||||
int num = 0, num2;
|
||||
int i;
|
||||
|
||||
for(i = 0; (i < 5 && *dst < end); i++) {
|
||||
num2 = read_byte(dst, end);
|
||||
|
||||
if(i == 4 && (num2 & 240) != 0) {
|
||||
hm_log(LOG_EMERG, lg, "Incorrect num size");
|
||||
abort();
|
||||
}
|
||||
|
||||
if((num2 & 128) == 0) {
|
||||
return num | (unsigned int)((unsigned int)num2 << 7 * i);
|
||||
}
|
||||
|
||||
num |= (unsigned int)((unsigned int)(num2 & 127) << 7 * i);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
u64 read_uint64(char **dst, const char *end)
|
||||
{
|
||||
u64 num = 0;
|
||||
int num2;
|
||||
int i;
|
||||
|
||||
for(i = 0; (i < 10 && *dst < end); i++) {
|
||||
num2 = read_byte(dst, end);
|
||||
|
||||
if(i == 9 && (num2 & 254) != 0) {
|
||||
hm_log(LOG_EMERG, lg, "Incorrect num size");
|
||||
abort();
|
||||
}
|
||||
|
||||
if((num2 & 128) == 0) {
|
||||
return num | (unsigned long long)((unsigned long long)num2 << 7 * i);
|
||||
}
|
||||
|
||||
num |= (unsigned long long)((unsigned long long)(num2 & 127) << 7 * i);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
void write_uint(char **dst, const char *end, int src)
|
||||
{
|
||||
char b;
|
||||
|
||||
while(1 == 1) {
|
||||
b = (char)(src & 127);
|
||||
src >>= 7;
|
||||
|
||||
if(src == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
b |= 128;
|
||||
|
||||
write_byte(dst, end, b);
|
||||
}
|
||||
|
||||
write_byte(dst, end, b);
|
||||
}
|
||||
|
||||
char *read_bytes(char **dst, const char *end, int *ndst)
|
||||
{
|
||||
char *out;
|
||||
|
||||
*ndst = read_uint(dst, end);
|
||||
|
||||
if(*dst + *ndst > end) {
|
||||
hm_log(LOG_EMERG, lg, "Dst read bytes %p %p %d", end, *dst + *ndst, *ndst);
|
||||
abort();
|
||||
}
|
||||
|
||||
out = malloc(*ndst);
|
||||
memcpy(out, *dst, *ndst);
|
||||
*dst += *ndst;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int write_bytes(char **dst, const char *end, const char *src, const int nsrc)
|
||||
{
|
||||
if(*dst + nsrc > end) {
|
||||
hm_log(LOG_EMERG, lg, "Cannot write %d %p %p", nsrc, *dst, end);
|
||||
abort();
|
||||
}
|
||||
|
||||
write_uint(dst, end, nsrc);
|
||||
|
||||
memcpy(*dst, src, nsrc);
|
||||
(*dst) += nsrc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void write_uint64(char **dst, const char *end, u64 src)
|
||||
{
|
||||
char b;
|
||||
|
||||
while(1 == 1) {
|
||||
b = (char)(src & 127);
|
||||
src >>= 7;
|
||||
|
||||
if(src == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
b |= 128;
|
||||
|
||||
write_byte(dst, end, b);
|
||||
}
|
||||
|
||||
write_byte(dst, end, b);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void suboption_free(struct suboption_s *s)
|
||||
{
|
||||
struct suboption_target_s *t, *del;
|
||||
|
||||
for(t = s->target; t != NULL; del = t, t = t->next, free(del));
|
||||
|
||||
free(s);
|
||||
}
|
||||
|
||||
int suboption_size(struct suboption_s *p)
|
||||
{
|
||||
int num = 0, num2;
|
||||
struct suboption_target_s *m;
|
||||
|
||||
num += sizeofu64(p->id);
|
||||
|
||||
if(p->target) {
|
||||
num += 1;
|
||||
num2 = num;
|
||||
for(m = p->target; m != NULL; m = m->next) {
|
||||
num += sizeofu64(m->value);
|
||||
}
|
||||
num += sizeofu32(num - num2);
|
||||
}
|
||||
|
||||
num += 1;
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int suboption_serialize(struct suboption_s *s, char **dst, const char *maxdst)
|
||||
{
|
||||
int num = 0;
|
||||
struct suboption_target_s *m;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->id);
|
||||
|
||||
if(s->target) {
|
||||
write_byte(dst, maxdst, 26);
|
||||
for(m = s->target; m != NULL; m = m->next) {
|
||||
num += sizeofu64(m->value);
|
||||
}
|
||||
|
||||
write_uint(dst, maxdst, num);
|
||||
|
||||
for(m = s->target; m != NULL; m = m->next) {
|
||||
write_uint64(dst, maxdst, m->value);
|
||||
}
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void tag_free(struct powerhistory_tag_s *t)
|
||||
{
|
||||
free(t);
|
||||
}
|
||||
|
||||
struct powerhistory_tag_s *tag_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct powerhistory_tag_s *t;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
t->name = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
t->value = read_uint64(dst, maxdst);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
int tag_size(struct powerhistory_tag_s *tag)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if(tag) {
|
||||
size += 2;
|
||||
size += sizeofu64(tag->name);
|
||||
size += sizeofu64(tag->value);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int tag_serialize(struct powerhistory_tag_s *t, char **dst, const char *maxdst)
|
||||
{
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, t->name);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, t->value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void tagchange_free(struct powerhistory_tagchange_s *t)
|
||||
{
|
||||
free(t);
|
||||
}
|
||||
|
||||
struct powerhistory_tagchange_s *tagchange_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct powerhistory_tagchange_s *t;
|
||||
|
||||
t = malloc(sizeof(*t));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
t->entity = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
t->tag = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
t->value = read_uint64(dst, maxdst);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int tagchange_serialize(struct powerhistory_tagchange_s *ent, char **dst, const char *maxdst)
|
||||
{
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, ent->entity);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, ent->tag);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, ent->value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tagchange_size(struct powerhistory_tagchange_s *t)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if(t) {
|
||||
size += 3;
|
||||
size += sizeofu64(t->entity);
|
||||
size += sizeofu64(t->tag);
|
||||
size += sizeofu64(t->value);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void turntimer_free(struct turntimer_s *t)
|
||||
{
|
||||
free(t);
|
||||
}
|
||||
|
||||
void *turntimer_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n;
|
||||
struct turntimer_s *o;
|
||||
|
||||
o = malloc(sizeof(*o));
|
||||
memset(o, 0, sizeof(*o));
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 8) {
|
||||
error();
|
||||
}
|
||||
o->seconds = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 16) {
|
||||
error();
|
||||
}
|
||||
o->turn = read_uint64(dst, maxdst);
|
||||
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n != 24) {
|
||||
error();
|
||||
}
|
||||
o->show = read_byte(dst, maxdst);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
int turntimer_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct turntimer_s *s;
|
||||
char *start;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
write_byte(dst, maxdst, 8);
|
||||
write_uint64(dst, maxdst, s->seconds);
|
||||
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, s->turn);
|
||||
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_byte(dst, maxdst, s->show);
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
void turntimer_dump(struct turntimer_s *t)
|
||||
{
|
||||
hm_log(LOG_DEBUG, lg, "Turn timer dump:");
|
||||
hm_log(LOG_DEBUG, lg, "\t\tseconds: %lld", t->seconds);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tturn: %lld", t->turn);
|
||||
hm_log(LOG_DEBUG, lg, "\t\tshow: %d", t->show);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
hm_gameserver - hearthmod gameserver
|
||||
Copyright (C) 2016 Filip Pancik
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <proto.h>
|
||||
|
||||
void userui_free(struct userui_s *u)
|
||||
{
|
||||
mouseinfo_free(u->mouseinfo);
|
||||
|
||||
free(u);
|
||||
}
|
||||
|
||||
void *userui_deserialize(char **dst, const char *maxdst)
|
||||
{
|
||||
int n, len;
|
||||
struct userui_s *c;
|
||||
|
||||
c = malloc(sizeof(*c));
|
||||
memset(c, 0, sizeof(*c));
|
||||
|
||||
while(*dst < maxdst) {
|
||||
n = read_byte(dst, maxdst);
|
||||
if(n == 10) {
|
||||
len = read_uint(dst, maxdst);
|
||||
c->mouseinfo = mouseinfo_deserialize(dst, *dst + len);
|
||||
}
|
||||
else if(n == 16) {
|
||||
c->emote = read_uint64(dst, maxdst);
|
||||
}
|
||||
else if(n == 24) {
|
||||
c->player_id = read_uint64(dst, maxdst);
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int userui_serialize(void *ao, char **dst, const char *maxdst)
|
||||
{
|
||||
struct userui_s *s;
|
||||
char *start;
|
||||
int n;
|
||||
|
||||
start = *dst;
|
||||
s = ao;
|
||||
|
||||
if(s->mouseinfo) {
|
||||
write_byte(dst, maxdst, 10);
|
||||
n = mouseinfo_size(s->mouseinfo);
|
||||
write_uint(dst, maxdst, n);
|
||||
mouseinfo_serialize(s->mouseinfo, dst, maxdst);
|
||||
}
|
||||
|
||||
if(s->emote != -1) {
|
||||
write_byte(dst, maxdst, 16);
|
||||
write_uint64(dst, maxdst, s->emote);
|
||||
}
|
||||
|
||||
if(s->player_id != -1) {
|
||||
write_byte(dst, maxdst, 24);
|
||||
write_uint64(dst, maxdst, s->player_id);
|
||||
}
|
||||
|
||||
return (*dst - start);
|
||||
}
|
||||
|
||||
int userui_size(struct userui_s *p)
|
||||
{
|
||||
int num = 0, n;
|
||||
|
||||
if(p->mouseinfo) {
|
||||
num += 1;
|
||||
n = mouseinfo_size(p->mouseinfo);
|
||||
num += n + sizeofu32(n);
|
||||
}
|
||||
|
||||
if(p->emote != 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(p->emote);
|
||||
}
|
||||
|
||||
if(p->player_id != 0) {
|
||||
num += 1;
|
||||
num += sizeofu64(p->player_id);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
void userui_dump(struct userui_s *u)
|
||||
{
|
||||
if(u) {
|
||||
if(u->mouseinfo) {
|
||||
hm_log(LOG_DEBUG, lg, "arrow origin: %lld", u->mouseinfo->arroworigin);
|
||||
hm_log(LOG_DEBUG, lg, "heldcard: %lld", u->mouseinfo->heldcard);
|
||||
hm_log(LOG_DEBUG, lg, "overcard: %lld", u->mouseinfo->overcard);
|
||||
hm_log(LOG_DEBUG, lg, "x: %lld", u->mouseinfo->x);
|
||||
hm_log(LOG_DEBUG, lg, "y: %lld", u->mouseinfo->y);
|
||||
}
|
||||
|
||||
if(u->emote != 0) {
|
||||
hm_log(LOG_DEBUG, lg, "emote: %lld", u->emote);
|
||||
}
|
||||
|
||||
if(u->player_id != 0) {
|
||||
hm_log(LOG_DEBUG, lg, "player_id: %lld", u->player_id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
all:
|
||||
$(CC) -Wall -g -I../../src/include -I../../../hm_base/src/include \
|
||||
-L../../lib -L../../../hm_base/lib \
|
||||
main.c \
|
||||
-lhmproto -lhmbase -lm\
|
||||
-o ./a.out
|
||||
|
||||
.PHONY: all
|
||||
@@ -0,0 +1,171 @@
|
||||
#include <hmbase.h>
|
||||
#include <proto.h>
|
||||
|
||||
struct hm_log_s *lg;
|
||||
|
||||
#define DUMP(m_dst, m_i, m_s)\
|
||||
int i##m_i = 0;\
|
||||
printf("dumping [%s]\n", m_s);\
|
||||
for(i##m_i = 0; i##m_i < m_i; i##m_i++) {\
|
||||
printf("%x", m_dst[i##m_i]);\
|
||||
}\
|
||||
printf("\n");
|
||||
|
||||
#define REPEAT\
|
||||
packet_free(p);\
|
||||
{\
|
||||
for(i = 0; i < 10; i++) {\
|
||||
parse_packet(p, buf, nbuf);\
|
||||
build_packet_test(p, buf);\
|
||||
packet_free(p);\
|
||||
}\
|
||||
}
|
||||
|
||||
#define build_packet_test(m_p, m_buffer)\
|
||||
char *ptrtest##m_buffer;\
|
||||
ptrtest##m_buffer = m_buffer;\
|
||||
n##m_buffer = serialize(m_p, &ptrtest##m_buffer, ptrtest##m_buffer + sizeof(m_buffer));
|
||||
|
||||
#define string(m_dst, m_ndst, m_s)\
|
||||
m_ndst = strlen(m_s);\
|
||||
m_dst = malloc(m_ndst);\
|
||||
memcpy(m_dst, m_s, m_ndst);
|
||||
|
||||
int main()
|
||||
{
|
||||
struct packet_s *p;
|
||||
struct hm_log_s l;
|
||||
int i;
|
||||
|
||||
hm_log_open(&l, NULL, LOG_DEBUG);
|
||||
lg = &l;
|
||||
|
||||
// chooseoption
|
||||
{
|
||||
struct chooseoption_s *c;
|
||||
c = malloc(sizeof(*c));
|
||||
c->id = 0xffff;
|
||||
c->index = 0xffff;
|
||||
c->target = 0xffff;
|
||||
c->suboption = 0xffff;
|
||||
c->position = 0xffff;
|
||||
|
||||
build_packet(p, c, P_CHOOSEOPTION, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
// turn timer
|
||||
{
|
||||
struct turntimer_s *c;
|
||||
c = malloc(sizeof(*c));
|
||||
c->seconds = 0xffff;
|
||||
c->turn = 0xffff;
|
||||
c->show = 0xff;
|
||||
|
||||
build_packet(p, c, P_TURNTIMER, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
// gamesetup
|
||||
{
|
||||
struct gamesetup_s *c;
|
||||
c = malloc(sizeof(*c));
|
||||
c->board = 0xffff;
|
||||
c->maxsecrets = 0xffff;
|
||||
c->maxfriendlyminions = 0xffff;
|
||||
c->stuckdisconnect = 0xffff;
|
||||
c->keepalive = 0xffff;
|
||||
|
||||
build_packet(p, c, P_TURNTIMER, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
// handshake
|
||||
{
|
||||
struct handshake_s *c;
|
||||
c = malloc(sizeof(*c));
|
||||
c->gamehandle = 0xffff;
|
||||
string(c->password, c->npassword, "password");
|
||||
c->clienthandle = 0xffff;
|
||||
c->mission = 0xffff;
|
||||
string(c->version, c->nversion, "version");
|
||||
|
||||
struct platform_s *pl;
|
||||
pl = malloc(sizeof(*pl));
|
||||
pl->os = 0xffff;
|
||||
pl->screen = 0xffff;
|
||||
string(pl->name, pl->nname, "name");
|
||||
pl->store = 0xffff;
|
||||
|
||||
c->platform = pl;
|
||||
|
||||
build_packet(p, c, P_HANDSHAKE, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
// chooseentities
|
||||
{
|
||||
struct chooseentities_s *c;
|
||||
struct chooseentities_ent_s *e;
|
||||
c = malloc(sizeof(*c));
|
||||
c->id = 0xffff;
|
||||
c->nentity = 4;
|
||||
c->entity = NULL;
|
||||
for(i = 0; i < c->nentity; i++) {
|
||||
e = malloc(sizeof(*e));
|
||||
e->entity = i;
|
||||
e->next = c->entity;
|
||||
c->entity = e;
|
||||
}
|
||||
|
||||
build_packet(p, c, P_CHOOSEENTITIES, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
// entitychoices
|
||||
{
|
||||
struct entitychoices_s *c;
|
||||
struct entitychoices_entities_s *e;
|
||||
c = malloc(sizeof(*c));
|
||||
c->id = 0xffff;
|
||||
c->type = 0xffff;
|
||||
c->countmin = 0xffff;
|
||||
c->countmax = 0xffff;
|
||||
c->source = 0xffff;
|
||||
c->player_id = 0xffff;
|
||||
c->entities = NULL;
|
||||
|
||||
for(i = 0; i < 10; i++) {
|
||||
e = malloc(sizeof(*e));
|
||||
e->entity = i;
|
||||
e->next = c->entities;
|
||||
c->entities = e;
|
||||
}
|
||||
|
||||
build_packet(p, c, P_ENTITYCHOICES, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
// userui
|
||||
{
|
||||
struct userui_s *c;
|
||||
struct mouseinfo_s *e;
|
||||
c = malloc(sizeof(*c));
|
||||
|
||||
e = malloc(sizeof(*e));
|
||||
e->arroworigin = 0xffff;
|
||||
e->heldcard = 0xffff;
|
||||
e->overcard = 0xffff;
|
||||
e->x = 0xffff;
|
||||
e->y = 0xffff;
|
||||
|
||||
c->mouseinfo = e;
|
||||
c->emote = 0xffff;
|
||||
c->player_id = 0xffff;
|
||||
|
||||
build_packet(p, c, P_USERUI, buf);
|
||||
REPEAT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user