Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# os
|
||||||
|
FROM ubuntu:16.04
|
||||||
|
RUN apt-get -y update && apt-get install -y git vim libev-dev tar wget libevent-dev build-essential libnet-ifconfig-wrapper-perl cmake python-pip libjson-c-dev curl valgrind zlib1g-dev python-webpy
|
||||||
|
# couchbase
|
||||||
|
RUN cd ~ && wget http://packages.couchbase.com/releases/4.5.0/couchbase-server-enterprise_4.5.0-ubuntu14.04_amd64.deb
|
||||||
|
RUN cd ~ && dpkg -i couchbase-server-enterprise_4.5.0-ubuntu14.04_amd64.deb
|
||||||
|
RUN cd ~ && git clone https://github.com/couchbase/libcouchbase.git
|
||||||
|
RUN cd ~ && cd libcouchbase && cmake . && make && make install
|
||||||
|
RUN cd ~ && wget http://packages.couchbase.com/clients/c/libcouchbase-2.5.8_ubuntu1404_amd64.tar && tar xvf *.tar && cd libcouchbase-2.5.8_ubuntu1404_amd64/ && dpkg -i *.deb
|
||||||
|
RUN pip install couchbase
|
||||||
|
# hearthmod
|
||||||
|
RUN cd ~ && git clone https://github.com/farb3yonddriv3n/hm_database.git
|
||||||
|
RUN cd ~ && git clone https://github.com/farb3yonddriv3n/hm_base.git
|
||||||
|
RUN cd ~ && git clone https://github.com/farb3yonddriv3n/hm_gameserver.git
|
||||||
|
RUN cd ~ && git clone https://github.com/farb3yonddriv3n/hm_lobbyserver.git
|
||||||
|
RUN cd ~ && git clone https://github.com/farb3yonddriv3n/hm_ctl.git
|
||||||
|
RUN cd ~ && git clone https://github.com/farb3yonddriv3n/hm_stud.git
|
||||||
|
# cleanup
|
||||||
|
RUN rm -rf ~/couchbase-server-enterprise_4.5.0-ubuntu14.04_amd64.deb ~/libcouchb*
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
bucket_create)
|
||||||
|
/opt/couchbase/bin/couchbase-cli bucket-create -c localhost:8091 -u Administrator -p password --bucket=hbs --bucket-password=aci --bucket-type=couchbase --bucket-ramsize=200 --bucket-replica=1 --wait
|
||||||
|
;;
|
||||||
|
bucket_restore)
|
||||||
|
/opt/couchbase/bin/cbrestore ~/hm_database/ http://localhost:8091/ --bucket-source=hbs
|
||||||
|
;;
|
||||||
|
compile)
|
||||||
|
make -C ~/hm_gameserver
|
||||||
|
make -C ~/hm_lobbyserver
|
||||||
|
;;
|
||||||
|
start)
|
||||||
|
mkdir -p ~/hm_log
|
||||||
|
valgrind --log-file=/root/hm_log/hm_gameserver_valgrind_$(date +%s) --trace-children=yes ~/hm_gameserver/hm_gameserver --log=/root/hm_log/hm_gameserver_$(date +%s)
|
||||||
|
valgrind --log-file=/root/hm_log/hm_lobbyserver_valgrind_$(date +%s) --trace-children=yes ~/hm_lobbyserver/hm_lobbyserver --log=/root/hm_log/hm_lobbyserver_$(date +%s)
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
ps -ef | grep hm_ | grep -v grep | awk '{print $2}' | xargs kill -9
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: ctl.sh {bucket_create|bucket_restore|compile|start|stop}" >&2
|
||||||
|
exit 3
|
||||||
|
esac
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
tags
|
||||||
|
*.swp
|
||||||
|
*.o
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Filip Pancik <far.b3yond.driv3n@gmail.com>
|
||||||
+622
@@ -0,0 +1,622 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
ifeq ($(target),game)
|
||||||
|
CFLAGS+=-g -Wall -DHM_GAMESERVER
|
||||||
|
else
|
||||||
|
CFLAGS+=-g -Wall -DHM_LOBBYSERVER
|
||||||
|
endif
|
||||||
|
INCS= -Isrc/include
|
||||||
|
LIBS= -lcouchbase
|
||||||
|
|
||||||
|
compile = $(CC) -c $(CFLAGS) $(INCS) $(LIBS) src/$(1).c -o src/$(1).o
|
||||||
|
|
||||||
|
game: hmbase
|
||||||
|
|
||||||
|
hmbase: src/*.c src/include/*.h
|
||||||
|
rm -rf lib/
|
||||||
|
$(call compile,log)
|
||||||
|
$(call compile,hashtable)
|
||||||
|
$(call compile,rb)
|
||||||
|
$(call compile,pool)
|
||||||
|
$(call compile,connector)
|
||||||
|
$(call compile,couchbase)
|
||||||
|
$(call compile,async_client)
|
||||||
|
mkdir -p lib/
|
||||||
|
ar cq lib/libhmbase.a src/*.o
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf src/*.o ./lib/
|
||||||
|
|
||||||
|
.PHONY: static hmbase
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# hm_base
|
||||||
|
|
||||||
|
base library
|
||||||
|
|
||||||
|
# This is not a standalone project!
|
||||||
|
|
||||||
|
[hm_base](https://github.com/farb3yonddriv3n/hm_base) is part of [hearthmod software stack](https://github.com/hearthmod/hearthmod)
|
||||||
@@ -0,0 +1,654 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <sys/types.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <sys/fcntl.h> // fcntl
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h> // close
|
||||||
|
#include <ev.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
|
||||||
|
#define ASYNC_HANG_TIMEOUT 14
|
||||||
|
|
||||||
|
struct ht_s **async_clients;
|
||||||
|
|
||||||
|
static unsigned long long client_index = 0;
|
||||||
|
|
||||||
|
static int async_client_accept(struct conn_client_s *client);
|
||||||
|
static void *connector_addclient(struct conn_server_s *cs, struct conn_client_s *cc);
|
||||||
|
|
||||||
|
void shutdown_server(struct conn_server_s *cs)
|
||||||
|
{
|
||||||
|
struct conn_client_holder_s *c, *dc;
|
||||||
|
struct hm_pool_s *p;
|
||||||
|
|
||||||
|
hm_log(LOG_INFO, cs->log, "{Connector}: shutting down server, clients: %d", cs->clients);
|
||||||
|
|
||||||
|
for(c = cs->clients_head; c != NULL; ) {
|
||||||
|
if(c->signal_shutdown == 0 && c->client) {
|
||||||
|
c->client->error_callback(c->client, CL_SERVERSHUTDOWN_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
dc = c;
|
||||||
|
c = c->next;
|
||||||
|
hm_pfree(cs->pool, dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = cs->pool;
|
||||||
|
ev_io_stop(cs->loop, &cs->listener);
|
||||||
|
connector_fd_close(cs->fd);
|
||||||
|
hm_pfree(p, cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void client_error(struct conn_client_s *c, enum clerr_e err)
|
||||||
|
{
|
||||||
|
async_shutdown_client(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setnonblock(int fd)
|
||||||
|
{
|
||||||
|
int nb;
|
||||||
|
|
||||||
|
nb = 1;
|
||||||
|
return ioctl(fd, FIONBIO, &nb);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HM_LOBBYSERVER
|
||||||
|
static char read_byte(char **dst, const char *end)
|
||||||
|
{
|
||||||
|
char out;
|
||||||
|
|
||||||
|
if(*dst + sizeof(char) > end) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
out = *((char *)(*dst));
|
||||||
|
|
||||||
|
(*dst)++;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
static 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) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void recv_append_lobby(struct conn_client_s *c, char *src, int nsrc)
|
||||||
|
{
|
||||||
|
unsigned short h;
|
||||||
|
int i, total;
|
||||||
|
struct conn_server_s *cs = c->parent;
|
||||||
|
|
||||||
|
if(nsrc < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: Received %d bytes", nsrc);
|
||||||
|
|
||||||
|
/** hbs lobby client */
|
||||||
|
if(nsrc > 12 && *(int *)src == -1) {
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: HBS lobby client packet");
|
||||||
|
cs->recv(c, src, nsrc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** hbs game client */
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: HBS game client packet");
|
||||||
|
h = (unsigned char )src[0];
|
||||||
|
h <<= 8;
|
||||||
|
h |= (unsigned char )src[1];
|
||||||
|
|
||||||
|
if(h == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
h += 2;
|
||||||
|
|
||||||
|
for(total = 0, i = 2; i < h; i++) {
|
||||||
|
if(src[i] == 0x28 && (i + 1) < h) {
|
||||||
|
char *ptr = &src[i + 1];
|
||||||
|
total = read_uint(&ptr, ptr + nsrc - h);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total += h;
|
||||||
|
|
||||||
|
cs->recv(c, src, total);
|
||||||
|
|
||||||
|
if(total < nsrc) {
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: Next packet of %d bytes prepared", nsrc - total);
|
||||||
|
recv_append_lobby(c, src + total, nsrc - total);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // HM_LOBBYSERVER
|
||||||
|
|
||||||
|
static void recv_append(struct conn_client_s *c)
|
||||||
|
{
|
||||||
|
#ifdef HM_GAMESERVER
|
||||||
|
int sz;
|
||||||
|
char *next;
|
||||||
|
struct conn_server_s *cs = c->parent;
|
||||||
|
|
||||||
|
next = rb_recv_read(&c->rb, &sz);
|
||||||
|
rb_recv_pop(&c->rb);
|
||||||
|
cs->recv(c, next, sz);
|
||||||
|
#elif defined HM_LOBBYSERVER
|
||||||
|
int sz;
|
||||||
|
char *next;
|
||||||
|
|
||||||
|
next = rb_recv_read(&c->rb, &sz);
|
||||||
|
c->net_nbuf = sz;
|
||||||
|
memcpy(c->net_buf, next, sz);
|
||||||
|
rb_recv_pop(&c->rb);
|
||||||
|
recv_append_lobby(c, c->net_buf, c->net_nbuf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void connector_client(struct ev_loop *loop, ev_io *w, int revents)
|
||||||
|
{
|
||||||
|
(void) revents;
|
||||||
|
struct sockaddr_storage addr;
|
||||||
|
socklen_t sl = sizeof(addr);
|
||||||
|
int client;
|
||||||
|
struct conn_client_s *cc;
|
||||||
|
struct conn_server_s *cs = w->data;
|
||||||
|
|
||||||
|
assert(cs);
|
||||||
|
|
||||||
|
client = accept(w->fd, (struct sockaddr *) &addr, &sl);
|
||||||
|
if(client == -1) {
|
||||||
|
switch (errno) {
|
||||||
|
case EMFILE:
|
||||||
|
hm_log(LOG_ERR, cs->log, "{Connector}: accept() failed; too many open files for this process");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENFILE:
|
||||||
|
hm_log(LOG_ERR, cs->log, "{client} accept() failed; too many open files for this system");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int flag = 1;
|
||||||
|
int ret = setsockopt(client, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
|
||||||
|
if(ret == -1) {
|
||||||
|
hm_log(LOG_ERR, cs->log, "{Connector}: Couldn't setsockopt on client (TCP_NODELAY)");
|
||||||
|
}
|
||||||
|
#ifdef TCP_CWND
|
||||||
|
int cwnd = 10;
|
||||||
|
ret = setsockopt(client, IPPROTO_TCP, TCP_CWND, &cwnd, sizeof(cwnd));
|
||||||
|
if(ret == -1) {
|
||||||
|
hm_log(LOG_ERR, cs->log, "Couldn't setsockopt on client (TCP_CWND)");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setnonblock(client);
|
||||||
|
setkeepalive(client);
|
||||||
|
|
||||||
|
#define PEER_NAME
|
||||||
|
#ifdef PEER_NAME
|
||||||
|
socklen_t len;
|
||||||
|
struct sockaddr_storage paddr;
|
||||||
|
char ipstr[INET6_ADDRSTRLEN];
|
||||||
|
int pport, peer;
|
||||||
|
|
||||||
|
len = sizeof(paddr);
|
||||||
|
peer = getpeername(client, (struct sockaddr*)&paddr, &len);
|
||||||
|
|
||||||
|
// deal with both IPv4 and IPv6:
|
||||||
|
if(paddr.ss_family == AF_INET) {
|
||||||
|
struct sockaddr_in *s = (struct sockaddr_in *)&paddr;
|
||||||
|
pport = ntohs(s->sin_port);
|
||||||
|
inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof(ipstr));
|
||||||
|
} else { // AF_INET6
|
||||||
|
struct sockaddr_in6 *s = (struct sockaddr_in6 *)&paddr;
|
||||||
|
pport = ntohs(s->sin6_port);
|
||||||
|
inet_ntop(AF_INET6, &s->sin6_addr, ipstr, sizeof(ipstr));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(peer == -1) {
|
||||||
|
hm_log(LOG_WARNING, cs->log, "{Connector}: Couldn't retrieve peer name");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cc = hm_palloc(cs->pool, sizeof(struct conn_client_s));
|
||||||
|
if(cc == NULL) {
|
||||||
|
hm_log(LOG_WARNING, cs->log, "{Connector}: Memory allocation failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(cc, 0, sizeof(struct conn_client_s));
|
||||||
|
|
||||||
|
cc->loop = loop;
|
||||||
|
cc->fd = client;
|
||||||
|
cc->pool = cs->pool;
|
||||||
|
cc->log = cs->log;
|
||||||
|
cc->read.data = cc;
|
||||||
|
cc->write.data = cc;
|
||||||
|
cc->parent = cs;
|
||||||
|
cc->error_callback = client_error;
|
||||||
|
cc->client_dc = cs->client_dc;
|
||||||
|
#ifdef PEER_NAME
|
||||||
|
cc->nip = strlen(ipstr);
|
||||||
|
memcpy(cc->ip, ipstr, cc->nip);
|
||||||
|
cc->port = pport;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(connector_addclient(cs, cc) == NULL) {
|
||||||
|
hm_pfree(cs->pool, cc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cc->recv = recv_append;
|
||||||
|
async_client_accept(cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int connector_server(struct conn_server_s *cs)
|
||||||
|
{
|
||||||
|
int t = 1;
|
||||||
|
int timeout = 1;
|
||||||
|
struct addrinfo *ai, hints;
|
||||||
|
memset(&hints, 0, sizeof hints);
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
|
||||||
|
const int gai_err = getaddrinfo(cs->host, cs->port, &hints, &ai);
|
||||||
|
|
||||||
|
if(gai_err != 0) {
|
||||||
|
hm_log(LOG_CRIT, cs->log, "{Connector}: [%s]", gai_strerror(gai_err));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cs->fd = socket(ai->ai_family, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
|
||||||
|
if(cs->fd == -1) {
|
||||||
|
hm_log(LOG_CRIT, cs->log, "{Connector}: socket() failed");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
hm_log(LOG_INFO, cs->log, "{Connector}: opening server on %s:%s fd: %d", cs->host, cs->port, cs->fd);
|
||||||
|
#ifdef SO_REUSEADDR
|
||||||
|
setsockopt(cs->fd, SOL_SOCKET, SO_REUSEADDR, &t, sizeof(int));
|
||||||
|
#endif
|
||||||
|
#ifdef SO_REUSEPORT
|
||||||
|
setsockopt(cs->fd, SOL_SOCKET, SO_REUSEPORT, &t, sizeof(int));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(bind(cs->fd, ai->ai_addr, ai->ai_addrlen)) {
|
||||||
|
hm_log(LOG_CRIT, cs->log, "{Connector}: bind() failed");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TCP_DEFER_ACCEPT
|
||||||
|
setsockopt(cs->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, sizeof(int));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
freeaddrinfo(ai);
|
||||||
|
listen(cs->fd, 128);
|
||||||
|
|
||||||
|
ev_io_init(&cs->listener, connector_client, cs->fd, EV_READ);
|
||||||
|
cs->listener.data = cs;
|
||||||
|
ev_io_start(cs->loop, &cs->listener);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void *connector_addclient(struct conn_server_s *cs, struct conn_client_s *cc)
|
||||||
|
{
|
||||||
|
struct conn_client_holder_s *cch;
|
||||||
|
|
||||||
|
cch = hm_palloc(cs->pool, sizeof(*cch));
|
||||||
|
|
||||||
|
if(cch == NULL) {
|
||||||
|
hm_log(LOG_WARNING, cs->log, "{Connector}: Memory allocation failed");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(cch, 0, sizeof(*cch));
|
||||||
|
|
||||||
|
cch->client = cc;
|
||||||
|
cch->next = cs->clients_head;
|
||||||
|
|
||||||
|
cc->shutdown_signal_holder = &cch->signal_shutdown;
|
||||||
|
|
||||||
|
cs->clients_head = cch;
|
||||||
|
cs->clients++;
|
||||||
|
|
||||||
|
cc->holder = cch;
|
||||||
|
|
||||||
|
hm_log(LOG_NOTICE, cs->log, "{Connector}: adding client %.*s:%d, total: %d", cc->nip, cc->ip, cc->port, cs->clients);
|
||||||
|
|
||||||
|
return cch;
|
||||||
|
}
|
||||||
|
|
||||||
|
int async_shutdown_client(struct conn_client_s *c)
|
||||||
|
{
|
||||||
|
if(c == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev_io_stop(c->loop, &c->read);
|
||||||
|
ev_io_stop(c->loop, &c->write);
|
||||||
|
ev_timer_stop(c->loop, &c->hang_timer);
|
||||||
|
|
||||||
|
/** pop in case it wasn't sent */
|
||||||
|
rb_send_pop(&c->rb, c->pool);
|
||||||
|
|
||||||
|
/** let holder know we're about to shutdown */
|
||||||
|
if(c->shutdown_signal_holder) {
|
||||||
|
*c->shutdown_signal_holder = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c->monitor == 1 && c->parent != NULL) {
|
||||||
|
c->parent->clients--;
|
||||||
|
}
|
||||||
|
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: async removing client %.*s:%d fd: %d type: %d alive since: %s", c->nip, c->ip, c->port, c->fd, c->type, c->date);
|
||||||
|
|
||||||
|
connector_fd_close(c->fd);
|
||||||
|
|
||||||
|
if(c->client_dc) {
|
||||||
|
c->client_dc(c->data, c->foreign_client_index, c->hbs_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HM_GAMESERVER
|
||||||
|
HT_REM(async_clients, c->client_index, strlen(c->client_index), c->pool);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
hm_pfree(c->pool, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void async_handle_socket_errno(struct conn_client_s *c)
|
||||||
|
{
|
||||||
|
if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(errno == ECONNRESET) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector} Connection reset by peer");
|
||||||
|
} else if(errno == ETIMEDOUT) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector} Connection to backend timed out");
|
||||||
|
} else if(errno == EPIPE) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector} Broken pipe to backend (EPIPE)");
|
||||||
|
} else {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector} errno: %d", errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void async_hang_timeout(struct ev_loop *loop, struct ev_timer *timer, int revents)
|
||||||
|
{
|
||||||
|
struct conn_client_s *c = (struct conn_client_s *)timer->data;
|
||||||
|
|
||||||
|
assert(c);
|
||||||
|
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: read timeout");
|
||||||
|
|
||||||
|
if(c->error_callback) {
|
||||||
|
c->error_callback(c, CL_HANGTIMEOUT_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NETDUMP(type, _buf, qq)\
|
||||||
|
int i;\
|
||||||
|
if(1 == 1) {\
|
||||||
|
if(type == 0) {\
|
||||||
|
hm_log(LOG_DEBUG, c->log, "sent: [%d] bytes %d", qq, fd);\
|
||||||
|
} else {\
|
||||||
|
hm_log(LOG_DEBUG, c->log, "received: [%d] bytes to fd %d", qq, fd);\
|
||||||
|
}\
|
||||||
|
printf("Ascii:\n--------\n");\
|
||||||
|
for(i = 0; i < qq; i++) {\
|
||||||
|
printf("%c", _buf[i] );\
|
||||||
|
}\
|
||||||
|
printf("Binary: ");\
|
||||||
|
for( i = 0; i < qq; i++ ) {\
|
||||||
|
printf("%.2x", (unsigned char)_buf[i] );\
|
||||||
|
}\
|
||||||
|
printf("\n");\
|
||||||
|
}
|
||||||
|
|
||||||
|
static void async_read(struct ev_loop *loop, ev_io *w, int revents)
|
||||||
|
{
|
||||||
|
(void) revents;
|
||||||
|
int t = 0;
|
||||||
|
struct conn_client_s *c = (struct conn_client_s *)w->data;
|
||||||
|
int fd = w->fd, used;
|
||||||
|
|
||||||
|
char *buf = rb_recv_ptr(&c->rb, &used);
|
||||||
|
|
||||||
|
if(c->want_shutdown) {
|
||||||
|
if(c->error_callback) {
|
||||||
|
c->error_callback(c, CL_WANTSHUTDOWN_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hm_log(LOG_DEBUG, c->log, "Received from fd %d", fd);
|
||||||
|
|
||||||
|
t = recv(fd, buf, RB_SLOT_SIZE - used, 0);
|
||||||
|
|
||||||
|
if(t > 0) {
|
||||||
|
//NETDUMP(1, buf, t)
|
||||||
|
rb_recv_append(&c->rb, t);
|
||||||
|
|
||||||
|
if(rb_recv_is_full(&c->rb)) {
|
||||||
|
ev_io_stop(c->loop, &c->read);
|
||||||
|
if(c->error_callback) {
|
||||||
|
c->error_callback(c, CL_READRBFULL_ERR);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c->hang_timer_enabled == 1) {
|
||||||
|
ev_timer_stop(c->loop, &c->hang_timer);
|
||||||
|
ev_timer_again(c->loop, &c->hang_timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
c->recv(c);
|
||||||
|
|
||||||
|
} else if(t == 0) {
|
||||||
|
async_handle_socket_errno(c);
|
||||||
|
if(c->error_callback) {
|
||||||
|
c->error_callback(c, CL_READZERO_ERR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
async_handle_socket_errno(c);
|
||||||
|
if(c->error_callback) {
|
||||||
|
c->error_callback(c, CL_READ_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void async_write(struct ev_loop *loop, ev_io *w, int revents)
|
||||||
|
{
|
||||||
|
(void)revents;
|
||||||
|
int t;
|
||||||
|
struct conn_client_s *c = (struct conn_client_s *)w->data;
|
||||||
|
int fd = w->fd;
|
||||||
|
int sz;
|
||||||
|
|
||||||
|
assert(c);
|
||||||
|
|
||||||
|
char *next = rb_send_next(&c->rb, &sz);
|
||||||
|
|
||||||
|
if(sz == 0) {
|
||||||
|
ev_io_stop(loop, &c->write);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
t = send(fd, next, sz, MSG_NOSIGNAL);
|
||||||
|
if(t > 0) {
|
||||||
|
//NETDUMP(0, next, t)
|
||||||
|
rb_send_skip(&c->rb, t);
|
||||||
|
if(rb_send_is_empty(&c->rb)) {
|
||||||
|
ev_io_stop(loop, &c->write);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//assert(t == -1);
|
||||||
|
async_handle_socket_errno(c);
|
||||||
|
if(c->error_callback) {
|
||||||
|
c->error_callback(c, CL_WRITE_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void timestring(char *b, const int nb)
|
||||||
|
{
|
||||||
|
char buf[128];
|
||||||
|
time_t s;
|
||||||
|
struct timespec spec;
|
||||||
|
long long ms;
|
||||||
|
struct tm ts;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &spec);
|
||||||
|
s = spec.tv_sec;
|
||||||
|
ms = round(spec.tv_nsec / 1.0e6);
|
||||||
|
|
||||||
|
ts = *localtime(&s);
|
||||||
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ts);
|
||||||
|
|
||||||
|
snprintf(b, nb, "[%s.%03lld] ", buf, ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
int async_client(struct conn_client_s *client, const int monitor, const int hang)
|
||||||
|
{
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
char ip[32];
|
||||||
|
|
||||||
|
assert(client);
|
||||||
|
|
||||||
|
/** TCP & non-blocking */
|
||||||
|
client->fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
||||||
|
if(-1 == client->fd) {
|
||||||
|
hm_log(LOG_ERR, client->log, "{Connector}: node init socket error: %d", client->fd);
|
||||||
|
client->error_callback(client, CL_SOCKET_ERR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(ip, sizeof(ip), "%.*s", client->nip, client->ip);
|
||||||
|
|
||||||
|
setkeepalive(client->fd);
|
||||||
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr = inet_addr(ip);
|
||||||
|
servaddr.sin_port = htons(client->port);
|
||||||
|
|
||||||
|
ev_io_init(&client->write, async_write, client->fd, EV_WRITE);
|
||||||
|
ev_io_init(&client->read, async_read, client->fd, EV_READ);
|
||||||
|
ev_init(&client->hang_timer, async_hang_timeout);
|
||||||
|
|
||||||
|
if(hang == 1) {
|
||||||
|
client->hang_timer.repeat = ASYNC_HANG_TIMEOUT;
|
||||||
|
client->hang_timer.data = client;
|
||||||
|
client->hang_timer_enabled = 1;
|
||||||
|
} else {
|
||||||
|
client->hang_timer_enabled = 0;
|
||||||
|
}
|
||||||
|
client->read.data = client;
|
||||||
|
client->write.data = client;
|
||||||
|
timestring(client->date, sizeof(client->date));
|
||||||
|
|
||||||
|
if(monitor == 1) {
|
||||||
|
connector_addclient(client->parent, client);
|
||||||
|
client->monitor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev_io_start(client->loop, &client->read);
|
||||||
|
ev_timer_again(client->loop, &client->hang_timer);
|
||||||
|
if(connect(client->fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) != -1 && errno != EINPROGRESS) {
|
||||||
|
async_shutdown_client(client);
|
||||||
|
hm_log(LOG_ERR, client->log, "{Connector}: connect() errno: %d", errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int async_client_accept(struct conn_client_s *client)
|
||||||
|
{
|
||||||
|
ev_io_init(&client->write, async_write, client->fd, EV_WRITE);
|
||||||
|
ev_io_init(&client->read, async_read, client->fd, EV_READ);
|
||||||
|
//ev_init(&client->hang_timer, async_hang_timeout);
|
||||||
|
|
||||||
|
client->hang_timer.repeat = ASYNC_HANG_TIMEOUT;
|
||||||
|
//client->hang_timer.data = client;
|
||||||
|
client->read.data = client;
|
||||||
|
client->write.data = client;
|
||||||
|
|
||||||
|
ev_io_start(client->loop, &client->read);
|
||||||
|
|
||||||
|
timestring(client->date, sizeof(client->date));
|
||||||
|
//ev_timer_again(client->loop, &client->hang_timer);
|
||||||
|
|
||||||
|
snprintf(client->client_index, sizeof(client->client_index), "%lld", client_index++);
|
||||||
|
|
||||||
|
#ifdef HM_GAMESERVER
|
||||||
|
HT_ADD_WA(async_clients, client->client_index, strlen(client->client_index), client, sizeof(client), client->pool);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <sys/types.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <sys/fcntl.h> // fcntl
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h> // close
|
||||||
|
#include <ev.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
#include <connector.h>
|
||||||
|
|
||||||
|
#define CL(a, b) case a: hm_log(LOG_ERR, log, "{Connector}: fd:%d, "b, fd); break;
|
||||||
|
|
||||||
|
void connector_fd_close(int fd)
|
||||||
|
{
|
||||||
|
if(fd > STDERR_FILENO) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getsockerr(int fd, int name, void *optval, const int l, struct hm_log_s *log)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
socklen_t len = l;
|
||||||
|
|
||||||
|
r = getsockopt(fd, SOL_SOCKET, name, optval, &len);
|
||||||
|
if(r < 0) {
|
||||||
|
switch(errno) {
|
||||||
|
CL(EBADF, "The argument sockfd is not a valid descriptor.");
|
||||||
|
CL(EFAULT, "The address pointed to by optval is not in a valid part of the process address space.");
|
||||||
|
CL(EINVAL, "optlen invalid in setsockopt()");
|
||||||
|
CL(ENOPROTOOPT, "The option is unknown at the level indicated.");
|
||||||
|
CL(ENOTSOCK, "The argument sockfd is a file, not a socket.");
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getsoerror(int fd, struct hm_log_s *log)
|
||||||
|
{
|
||||||
|
int error = 0;
|
||||||
|
|
||||||
|
if(getsockerr(fd, SO_ERROR, &error, sizeof(int), log) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(error) {
|
||||||
|
case 0: return 0; break;
|
||||||
|
CL(EACCES, "For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket file, or search permission is denied for one of the directories in the path prefix. (See also path_resolution(7).)"); CL(EPERM, "The user tried to connect to a broadcast address without having the socket broadcast flag enabled or the connection request failed because of a local firewall rule.");
|
||||||
|
CL(EADDRINUSE, "Local address is already in use.");
|
||||||
|
CL(EAFNOSUPPORT, "The passed address didn't have the correct address family in its sa_family field.");
|
||||||
|
CL(EAGAIN, "No more free local ports or insufficient entries in the routing cache. For AF_INET see the description of /proc/sys/net/ipv4/ip_local_port_range ip(7) for information on how to increase the number of local ports.");
|
||||||
|
CL(EALREADY, "The socket is nonblocking and a previous connection attempt has not yet been completed.");
|
||||||
|
CL(EBADF, "The file descriptor is not a valid index in the descriptor table.");
|
||||||
|
CL(ECONNREFUSED, "No-one listening on the remote address.");
|
||||||
|
CL(EFAULT, "The socket structure address is outside the user's address space.");
|
||||||
|
CL(EINPROGRESS, "The socket is nonblocking and the connection cannot be completed immediately. It is possible to select(2) or poll(2) for completion by selecting the socket forwriting. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure).");
|
||||||
|
CL(EINTR, "The system call was interrupted by a signal that was caught; see signal(7).");
|
||||||
|
CL(EISCONN, "The socket is already connected.");
|
||||||
|
CL(ENETUNREACH, "Network is unreachable.");
|
||||||
|
CL(ENOTSOCK, "The file descriptor is not associated with a socket.");
|
||||||
|
CL(ETIMEDOUT, "Timeout while attempting connection. The server may be too busy to accept new connections. Note that for IP sockets the timeout may be very long when syncookies are enabled on the server.");
|
||||||
|
}
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int islinger(struct conn_node_s *c)
|
||||||
|
{
|
||||||
|
struct linger l;
|
||||||
|
|
||||||
|
if(getsockerr(c->fd, SO_LINGER, &l, sizeof(l), c->log) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return l.l_onoff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void failed_cb(struct ev_loop *loop, ev_timer *w, int revents)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
struct conn_node_s *c = (struct conn_node_s *)w->data;
|
||||||
|
#ifdef D_ASSERT
|
||||||
|
assert(c != NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ev_io_stop(loop, &c->io);
|
||||||
|
|
||||||
|
r = islinger(c);
|
||||||
|
if(r < 0) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector}: error on socket %d", c->fd);
|
||||||
|
} else if(r > 0) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector}: SO_LINGER set on fd %d", c->fd);
|
||||||
|
}
|
||||||
|
connector_fd_close(c->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void established_cb(struct ev_loop *loop, ev_io *w, int revents)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
struct conn_node_s *c = (struct conn_node_s *)w->data;
|
||||||
|
|
||||||
|
#ifdef D_ASSERT
|
||||||
|
assert(c != NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ev_timer_stop(loop, &c->timer);
|
||||||
|
ev_io_stop(loop, w);
|
||||||
|
|
||||||
|
r = getsoerror(c->fd, c->log);
|
||||||
|
|
||||||
|
if(r == 0) {
|
||||||
|
c->status |= CONN_F_CONNECTED;
|
||||||
|
|
||||||
|
if(!(c->status & CONN_F_FDOPEN)) {
|
||||||
|
r = islinger(c);
|
||||||
|
if(r < 0) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector}: error on socket %d", c->fd);
|
||||||
|
} else if(r > 0) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector}: SO_LINGER set on fd %d", c->fd);
|
||||||
|
}
|
||||||
|
connector_fd_close(c->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**< return immediately when single check is performed or all nodes are connected */
|
||||||
|
if(c->status & CONN_F_SINGLECHECK || ++(c->parent->established) == c->parent->size) {
|
||||||
|
ev_timer_stop(loop, &c->parent->timer);
|
||||||
|
c->parent->callback(c->parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int check_connection(struct conn_data_s *cd, struct conn_node_s *c)
|
||||||
|
{
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
|
||||||
|
#ifdef D_ASSERT
|
||||||
|
assert(c != NULL && cd->loop != NULL);
|
||||||
|
#endif
|
||||||
|
if(strlen(c->host) < 1 || c->port < 1 || c->port > ((1<<16) - 1)) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector}: incorrect hostname or port: [%s]:%d", c->host, c->port);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
||||||
|
if(-1 == c->fd) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Connector}: FD = -1");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: setsockopt depending on c->status
|
||||||
|
|
||||||
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr=inet_addr(c->host);
|
||||||
|
servaddr.sin_port=htons(c->port);
|
||||||
|
|
||||||
|
c->io.data = c;
|
||||||
|
ev_io_init(&c->io, established_cb, c->fd, EV_WRITE);
|
||||||
|
ev_io_start(cd->loop, &c->io);
|
||||||
|
|
||||||
|
c->timer.data = c;
|
||||||
|
ev_timer_init(&c->timer, failed_cb, cd->timeout, 0);
|
||||||
|
ev_timer_start(cd->loop, &c->timer);
|
||||||
|
|
||||||
|
hm_log(LOG_INFO, c->log, "{Connector}: connecting to %s:%d", c->host, c->port);
|
||||||
|
connect(c->fd, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void terminator(struct ev_loop *loop, ev_timer *w, int revents)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct conn_data_s *c = (struct conn_data_s *)w->data;
|
||||||
|
|
||||||
|
#ifdef D_ASSERT
|
||||||
|
assert(c != NULL);
|
||||||
|
#endif
|
||||||
|
/**< Terminate all connector events */
|
||||||
|
for(i = 0; i < c->size; i++) {
|
||||||
|
if(c && c->loop && c->src[i]) {
|
||||||
|
ev_io_stop(c->loop, &c->src[i]->io);
|
||||||
|
ev_timer_stop(c->loop, &c->src[i]->timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c->callback(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setkeepalive(int fd)
|
||||||
|
{
|
||||||
|
int optval;
|
||||||
|
socklen_t optlen = sizeof(optval);
|
||||||
|
|
||||||
|
optval = 1;
|
||||||
|
if(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int connector(struct conn_data_s *c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#ifdef D_ASSERT
|
||||||
|
assert(c != NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
c->established = 0;
|
||||||
|
for(i = 0; i < c->size; i++) {
|
||||||
|
c->src[i]->parent = c;
|
||||||
|
c->src[i]->log = c->log;
|
||||||
|
check_connection(c, c->src[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
c->timer.data = c;
|
||||||
|
|
||||||
|
ev_timer_init(&c->timer, terminator, c->exptime, 0);
|
||||||
|
ev_timer_start(c->loop, &c->timer);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void connector_free(struct conn_data_s *c)
|
||||||
|
{
|
||||||
|
if(!c) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < c->size; i++) {
|
||||||
|
ev_io_stop(c->loop, &c->src[i]->io);
|
||||||
|
ev_timer_stop(c->loop, &c->src[i]->timer);
|
||||||
|
connector_fd_close(c->src[i]->fd);
|
||||||
|
hm_pfree(c->pool, c->src[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ev_timer_stop(c->loop, &c->timer);
|
||||||
|
hm_pfree(c->pool, c->src);
|
||||||
|
hm_pfree(c->pool, c);
|
||||||
|
}
|
||||||
@@ -0,0 +1,567 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libcouchbase/couchbase.h>
|
||||||
|
#include <libcouchbase/views.h>
|
||||||
|
#include <ev.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
#include <connector.h>
|
||||||
|
#include <hmcouchbase.h>
|
||||||
|
|
||||||
|
// TODO: even though these globals can stay here, move them elsewhere in the future
|
||||||
|
static lcb_t *active_instance;
|
||||||
|
static struct conn_node_s **c;
|
||||||
|
static struct conn_data_s *cd;
|
||||||
|
static int BUCKETS_PER_CLUSTER;
|
||||||
|
static int HOSTS;
|
||||||
|
static int grcount = 0; /**< groups counter */
|
||||||
|
static void (*callback)(struct instance_s *) = NULL;
|
||||||
|
static struct instance_s *instances = NULL;
|
||||||
|
static struct connstr_s **groups = NULL;
|
||||||
|
static struct hm_log_s *cb_log = NULL;
|
||||||
|
|
||||||
|
static void error_callback(lcb_t instance, struct cbop_s *cbop, lcb_error_t error);
|
||||||
|
static int is_active_instance(lcb_t instance);
|
||||||
|
static void switch_instances(lcb_t instance);
|
||||||
|
static void bootstrap_callback(lcb_t instance, lcb_error_t err);
|
||||||
|
static void store_callback(lcb_t instance, const void *cookie,
|
||||||
|
lcb_storage_t operation, lcb_error_t error, const lcb_store_resp_t *resp);
|
||||||
|
static void remove_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_remove_resp_t *resp);
|
||||||
|
static void arithmetic_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_arithmetic_resp_t *resp);
|
||||||
|
static void get_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_get_resp_t *resp);
|
||||||
|
static int cb_get(struct cbop_s *cbop);
|
||||||
|
static int cb_arithmetic(struct cbop_s *cbop);
|
||||||
|
static int cb_remove(struct cbop_s *cbop);
|
||||||
|
static int cb_store(struct cbop_s *cbop);
|
||||||
|
static int cb_view(struct cbop_s *cbop);
|
||||||
|
static int storage_init(struct conn_data_s *cd, struct conn_node_s *cn, struct connstr_s *cs, const int idx );
|
||||||
|
static void connector_cb(struct conn_data_s *c);
|
||||||
|
|
||||||
|
static void error_callback(lcb_t instance, struct cbop_s *cbop, lcb_error_t error)
|
||||||
|
{
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: error 0x%x", error);
|
||||||
|
|
||||||
|
// network related errors
|
||||||
|
if(error == LCB_NETWORK_ERROR || error == LCB_ETIMEDOUT || error == LCB_ENETUNREACH) {
|
||||||
|
if(is_active_instance(instance) == CB_ERR_OK) {
|
||||||
|
// switch instances and try again
|
||||||
|
// TODO: keep track of switching to avoid dead lock if all groups are offline
|
||||||
|
switch_instances(instance);
|
||||||
|
couchbase_operation(cbop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TYPE(T)\
|
||||||
|
if(resp->version == CB_QUERY_VER) {\
|
||||||
|
cbop->lcb_error = error;\
|
||||||
|
cbop->u.T.r = resp;\
|
||||||
|
if(cbop->post) {\
|
||||||
|
cbop->post(cbop);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
static void store_callback(lcb_t instance, const void *cookie,
|
||||||
|
lcb_storage_t operation, lcb_error_t error, const lcb_store_resp_t *resp)
|
||||||
|
{
|
||||||
|
struct cbop_s *cbop = (struct cbop_s *)cookie;
|
||||||
|
|
||||||
|
if(error == LCB_SUCCESS || error == LCB_KEY_ENOENT || error == LCB_KEY_EEXISTS || (error == LCB_ETMPFAIL && CBSQ(cas) != 0)) {
|
||||||
|
TYPE(s)
|
||||||
|
} else {
|
||||||
|
error_callback(instance, cbop, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void remove_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_remove_resp_t *resp)
|
||||||
|
{
|
||||||
|
struct cbop_s *cbop = (struct cbop_s *)cookie;
|
||||||
|
|
||||||
|
if(error == LCB_SUCCESS || error == LCB_KEY_ENOENT || (error == LCB_ETMPFAIL && CBRQ(cas) != 0)) {
|
||||||
|
TYPE(r)
|
||||||
|
} else {
|
||||||
|
error_callback(instance, cbop, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void arithmetic_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_arithmetic_resp_t *resp)
|
||||||
|
{
|
||||||
|
struct cbop_s *cbop = (struct cbop_s *)cookie;
|
||||||
|
|
||||||
|
if(error == LCB_SUCCESS || error == LCB_KEY_ENOENT) {
|
||||||
|
TYPE(a)
|
||||||
|
} else {
|
||||||
|
error_callback(instance, cbop, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void get_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_get_resp_t *resp)
|
||||||
|
{
|
||||||
|
struct cbop_s *cbop = (struct cbop_s *)cookie;
|
||||||
|
|
||||||
|
if(error == LCB_SUCCESS || error == LCB_KEY_ENOENT) {
|
||||||
|
TYPE(g)
|
||||||
|
} else {
|
||||||
|
error_callback(instance, cbop, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cb_get(struct cbop_s *cbop)
|
||||||
|
{
|
||||||
|
lcb_error_t error;
|
||||||
|
const lcb_get_cmd_t *commands[] = { &(cbop->u.g.q) };
|
||||||
|
|
||||||
|
if(0) hm_log(LOG_DEBUG, cb_log, "{Couchbase}: get [%.*s]", (int)commands[0]->v.v0.nkey, (char*)commands[0]->v.v0.key);
|
||||||
|
error = lcb_get(active_instance[cbop->bucket], cbop, 1, commands);
|
||||||
|
if(error != LCB_SUCCESS) {
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: couchbase operation failed with error: %d", error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cb_arithmetic(struct cbop_s *cbop)
|
||||||
|
{
|
||||||
|
lcb_error_t error;
|
||||||
|
const lcb_arithmetic_cmd_t *cmds[] = { &(cbop->u.a.q) };
|
||||||
|
|
||||||
|
error = lcb_arithmetic(active_instance[cbop->bucket], cbop, 1, cmds);
|
||||||
|
if(error != LCB_SUCCESS) {
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: couchbase operation failed with error: %d", error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cb_remove(struct cbop_s *cbop)
|
||||||
|
{
|
||||||
|
lcb_error_t error;
|
||||||
|
const lcb_remove_cmd_t *cmds[] = { &(cbop->u.r.q) };
|
||||||
|
|
||||||
|
error = lcb_remove(active_instance[cbop->bucket], cbop, 1, cmds);
|
||||||
|
if(error != LCB_SUCCESS) {
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: couchbase operation failed with error: %d", error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cb_store(struct cbop_s *cbop)
|
||||||
|
{
|
||||||
|
lcb_error_t error;
|
||||||
|
const lcb_store_cmd_t *cmds[] = { &(cbop->u.s.q) };
|
||||||
|
|
||||||
|
if(1 == 1) hm_log(LOG_DEBUG, cb_log, "{Couchbase}: set [%.*s], cas=0x%lx [%.*s]", (int)cmds[0]->v.v0.nkey, (char*)cmds[0]->v.v0.key, cmds[0]->v.v0.cas, (int)cmds[0]->v.v0.nbytes, (char*)cmds[0]->v.v0.bytes);
|
||||||
|
printf("bucket %p\n", active_instance[cbop->bucket]);
|
||||||
|
error = lcb_store(active_instance[cbop->bucket], cbop, 1, cmds);
|
||||||
|
|
||||||
|
printf("bucket %p\n", active_instance[cbop->bucket]);
|
||||||
|
if (error != LCB_SUCCESS) {
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: couchbase operation failed with error: %d", error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("error %d\n", error);
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cb_view(struct cbop_s *cbop)
|
||||||
|
{
|
||||||
|
lcb_error_t error;
|
||||||
|
|
||||||
|
error = lcb_view_query(active_instance[cbop->bucket], cbop, &(cbop->u.v.q));
|
||||||
|
if (error != LCB_SUCCESS) {
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: couchbase operation failed with error: %d", error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**< @brief
|
||||||
|
*
|
||||||
|
* Natural selection based on network latency, whichever instance comes first, takes 0 index
|
||||||
|
*/
|
||||||
|
static void set_instance(lcb_t instance)
|
||||||
|
{
|
||||||
|
const void *cookie;
|
||||||
|
struct instance_s *ins;
|
||||||
|
|
||||||
|
cookie = lcb_get_cookie(instance);
|
||||||
|
ins = (struct instance_s *)cookie;
|
||||||
|
|
||||||
|
if(active_instance[ins->index] == NULL) {
|
||||||
|
active_instance[ins->index] = instance;
|
||||||
|
hm_log(LOG_DEBUG, ins->log, "{Couchbase}: New instance on index %d from group: %d : %p", ins->index, ins->group, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// broken instance is set as active?
|
||||||
|
static int is_active_instance(lcb_t instance)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < BUCKETS_PER_CLUSTER; i++) {
|
||||||
|
if(active_instance[i] == instance) {
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CB_ERR_NOACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void switch_instances(lcb_t instance)
|
||||||
|
{
|
||||||
|
int i, j, k;
|
||||||
|
const void *cookie;
|
||||||
|
struct instance_s *ins;
|
||||||
|
|
||||||
|
cookie = lcb_get_cookie(instance);
|
||||||
|
ins = (struct instance_s *)cookie;
|
||||||
|
|
||||||
|
for(i = 0; i < HOSTS; i++) {
|
||||||
|
for(j = 0; j < BUCKETS_PER_CLUSTER; j++) {
|
||||||
|
if(((struct cluster_s *)(cd->src[i]->data))->instance[j] != instance &&
|
||||||
|
cd->src[i]->group != ins->group ) {
|
||||||
|
for(k = 0; k < BUCKETS_PER_CLUSTER; k++) {
|
||||||
|
hm_log(LOG_DEBUG, ins->log, "{Couchbase}: old instance: %p, new instance: %p, index: %d new host: %s", active_instance[k], ((struct cluster_s *)(cd->src[i]->data))->instance[k], k, cd->src[i]->host);
|
||||||
|
active_instance[k] = ((struct cluster_s *)(cd->src[i]->data))->instance[k];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bootstrap_callback(lcb_t instance, lcb_error_t err)
|
||||||
|
{
|
||||||
|
static int counter = 0;
|
||||||
|
const void *cookie;
|
||||||
|
struct instance_s *ins;
|
||||||
|
|
||||||
|
cookie = lcb_get_cookie(instance);
|
||||||
|
ins = (struct instance_s *)cookie;
|
||||||
|
|
||||||
|
if(err == LCB_SUCCESS) {
|
||||||
|
ins->status = 1;
|
||||||
|
set_instance(instance);
|
||||||
|
} else {
|
||||||
|
ins->status = 0;
|
||||||
|
hm_log(LOG_ERR, ins->log, "{Couchbase}: Bootstrap error 0x%x", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
ins->next = instances;
|
||||||
|
instances = ins;
|
||||||
|
|
||||||
|
if(++counter >= (BUCKETS_PER_CLUSTER * grcount) && callback) {
|
||||||
|
callback(instances);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy_callback(const void *cookie)
|
||||||
|
{
|
||||||
|
struct instance_s *ins;
|
||||||
|
|
||||||
|
ins = (struct instance_s *)cookie;
|
||||||
|
|
||||||
|
///< this causes SIGSEGV
|
||||||
|
//lcb_destroy_io_ops(ins->ioops);
|
||||||
|
|
||||||
|
hm_pfree(ins->pool, ins);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int storage_init(struct conn_data_s *cd, struct conn_node_s *cn, struct connstr_s *cs, const int idx)
|
||||||
|
{
|
||||||
|
lcb_error_t error;
|
||||||
|
struct lcb_create_io_ops_st ciops;
|
||||||
|
struct lcb_create_st copts;
|
||||||
|
char connstr[CONNSTR_SIZE];
|
||||||
|
struct instance_s *ins;
|
||||||
|
struct cluster_s *cl = cn->data;
|
||||||
|
int nconnstr;
|
||||||
|
|
||||||
|
memset(&ciops, 0, sizeof(ciops));
|
||||||
|
memset(&copts, 0, sizeof(copts));
|
||||||
|
ins = hm_palloc(cd->pool, sizeof(*ins));
|
||||||
|
|
||||||
|
ciops.v.v0.type = LCB_IO_OPS_LIBEV;
|
||||||
|
ciops.v.v0.cookie = cd->loop;
|
||||||
|
|
||||||
|
assert(cl != NULL);
|
||||||
|
|
||||||
|
error = lcb_create_io_ops(&ins->ioops, &ciops);
|
||||||
|
if(error != LCB_SUCCESS) {
|
||||||
|
hm_pfree(cd->pool, ins);
|
||||||
|
return CB_ERR_LCBCREATEIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(connstr, sizeof(connstr), "couchbase://%.*s/%s", cs->len - 1, cs->host, cl->bucket[idx]);
|
||||||
|
hm_log(LOG_DEBUG, cd->log, "{Connector}: connstr: [%s]", connstr);
|
||||||
|
copts.version = 3;
|
||||||
|
copts.v.v3.connstr = connstr;
|
||||||
|
copts.v.v3.username = cl->bucket[idx];
|
||||||
|
copts.v.v3.passwd = cl->passwd[idx];
|
||||||
|
copts.v.v3.io = ins->ioops;
|
||||||
|
|
||||||
|
error = lcb_create(&cl->instance[idx], &copts);
|
||||||
|
if(error != LCB_SUCCESS) {
|
||||||
|
hm_pfree(cd->pool, ins);
|
||||||
|
return CB_ERR_LCBCREATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nconnstr = strlen(connstr);
|
||||||
|
ins->group = cs->id;
|
||||||
|
ins->index = idx;
|
||||||
|
memcpy(ins->connstr, connstr, nconnstr);
|
||||||
|
ins->connstr[nconnstr] = 0;
|
||||||
|
ins->loop = cd->loop;
|
||||||
|
ins->log = cd->log;
|
||||||
|
ins->pool = cd->pool;
|
||||||
|
lcb_set_cookie(cl->instance[idx], ins);
|
||||||
|
|
||||||
|
lcb_set_bootstrap_callback(cl->instance[idx], bootstrap_callback);
|
||||||
|
lcb_set_get_callback(cl->instance[idx], get_callback);
|
||||||
|
lcb_set_store_callback(cl->instance[idx], store_callback);
|
||||||
|
lcb_set_remove_callback(cl->instance[idx], remove_callback);
|
||||||
|
lcb_set_arithmetic_callback(cl->instance[idx], arithmetic_callback);
|
||||||
|
lcb_set_destroy_callback(cl->instance[idx], destroy_callback);
|
||||||
|
|
||||||
|
if((error = lcb_connect(cl->instance[idx])) != LCB_SUCCESS) {
|
||||||
|
lcb_destroy(cl->instance[idx]);
|
||||||
|
hm_pfree(cd->pool, ins);
|
||||||
|
return CB_ERR_LCBCONNECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void buildconnstr(struct conn_data_s *c, struct connstr_s **groups, const char *host, const int group)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if(group >= MAX_GROUPS || group < 0) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Couchbase}: groups count error: %d", group);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(groups[group] == NULL) {
|
||||||
|
groups[group] = hm_palloc(c->pool, sizeof(struct connstr_s));
|
||||||
|
groups[group]->host = hm_palloc(c->pool, CONNSTR_SIZE); /**< max size */
|
||||||
|
groups[group]->len = strlen(host);
|
||||||
|
groups[group]->id = group;
|
||||||
|
|
||||||
|
memcpy(groups[group]->host, host, groups[group]->len);
|
||||||
|
groups[group]->host[groups[group]->len++] = ','; /**< connstr delimiter */
|
||||||
|
|
||||||
|
grcount++;
|
||||||
|
} else {
|
||||||
|
len = strlen(host);
|
||||||
|
memcpy(&(groups[group]->host[groups[group]->len]), host, len);
|
||||||
|
groups[group]->len += len;
|
||||||
|
groups[group]->host[groups[group]->len++] = ','; /**< connstr delimiter */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void connector_cb(struct conn_data_s *c)
|
||||||
|
{
|
||||||
|
int i, j, error, connected = 0;
|
||||||
|
|
||||||
|
for(i = 0; i < c->size; i++) {
|
||||||
|
if(c->src[i] && (c->src[i]->status & CONN_F_CONNECTED)) {
|
||||||
|
hm_log(LOG_DEBUG, c->log, "{Connector}: Connected to %s:%d", c->src[i]->host, c->src[i]->port);
|
||||||
|
buildconnstr(c, groups, c->src[i]->host, c->src[i]->group);
|
||||||
|
connected = 1;
|
||||||
|
} else {
|
||||||
|
hm_log(LOG_NOTICE, c->log, "{Connector}: Failed to connect to %s:%d", c->src[i]->host, c->src[i]->port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**< No available hosts found */
|
||||||
|
if(connected != 1) {
|
||||||
|
callback(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_GROUPS; i++) {
|
||||||
|
if(groups[i] != NULL) {
|
||||||
|
for(j = 0; j < BUCKETS_PER_CLUSTER; j++) {
|
||||||
|
error = storage_init(c, c->src[i], groups[i], j);
|
||||||
|
if(error != CB_ERR_OK) {
|
||||||
|
hm_log(LOG_ERR, c->log, "{Couchbase}: storage_init failed for %s:%d with code 0x%x", c->src[i]->host, c->src[i]->port, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int couchbase_init(struct couchbase_data_s *cbd)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
struct cluster_s *cl;
|
||||||
|
|
||||||
|
groups = hm_palloc(cbd->pool, sizeof(void *) * MAX_GROUPS);
|
||||||
|
memset(groups, 0, sizeof(void *) * MAX_GROUPS);
|
||||||
|
|
||||||
|
BUCKETS_PER_CLUSTER = cbd->nbuckets;
|
||||||
|
HOSTS = cbd->nhosts;
|
||||||
|
|
||||||
|
assert(cbd->pool != NULL && cbd->log != NULL);
|
||||||
|
|
||||||
|
cd = hm_palloc(cbd->pool, sizeof(*cd));
|
||||||
|
cd->size = HOSTS;
|
||||||
|
cd->loop = cbd->loop;
|
||||||
|
cd->callback = connector_cb;
|
||||||
|
cd->log = cbd->log;
|
||||||
|
cd->pool = cbd->pool;
|
||||||
|
cd->timeout = 1.0;
|
||||||
|
cd->exptime = 2.0;
|
||||||
|
callback = cbd->callback;
|
||||||
|
cb_log = cbd->log;
|
||||||
|
|
||||||
|
active_instance = hm_palloc(cd->pool, BUCKETS_PER_CLUSTER * sizeof(lcb_t));
|
||||||
|
for(i = 0; i < BUCKETS_PER_CLUSTER; i++) {
|
||||||
|
active_instance[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = hm_palloc(cd->pool, HOSTS * sizeof(void *));
|
||||||
|
for( i = 0; i < HOSTS; i++ ) {
|
||||||
|
c[i] = hm_palloc(cd->pool, sizeof(*(c[i])));
|
||||||
|
bzero(c[i], sizeof(*c[i]));
|
||||||
|
c[i]->port = 8091;
|
||||||
|
c[i]->status = CONN_F_COUCHBASE; /**< Couchbase opens its own FD */
|
||||||
|
c[i]->group = cbd->hgroups[i];
|
||||||
|
|
||||||
|
memcpy( c[i]->host, cbd->hosts[i], strlen(cbd->hosts[i])+1 );
|
||||||
|
|
||||||
|
cl = hm_palloc(cd->pool, sizeof(*cl));
|
||||||
|
cl->bucket = hm_palloc(cd->pool, sizeof(void *) * BUCKETS_PER_CLUSTER);
|
||||||
|
cl->passwd = hm_palloc(cd->pool, sizeof(void *) * BUCKETS_PER_CLUSTER);
|
||||||
|
cl->instance = hm_palloc(cd->pool, sizeof(lcb_t) * BUCKETS_PER_CLUSTER);
|
||||||
|
memset(cl->instance, 0, sizeof(lcb_t) * BUCKETS_PER_CLUSTER);
|
||||||
|
|
||||||
|
for( j = 0; j < BUCKETS_PER_CLUSTER; j++ ) {
|
||||||
|
cl->bucket[j] = hm_palloc(cd->pool, strlen(cbd->buckets[j])+1);
|
||||||
|
cl->passwd[j] = hm_palloc(cd->pool, strlen(cbd->bpasswd[j])+1);
|
||||||
|
memcpy(cl->bucket[j], cbd->buckets[j], strlen(cbd->buckets[j])+1);
|
||||||
|
memcpy(cl->passwd[j], cbd->bpasswd[j], strlen(cbd->bpasswd[j])+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
c[i]->data = cl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cd->src = c;
|
||||||
|
connector( cd );
|
||||||
|
|
||||||
|
return CB_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int couchbase_bucket_index(const char *bucketName) {
|
||||||
|
if(HOSTS == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cluster_s *cl = (struct cluster_s*)c[0]->data;
|
||||||
|
int i;
|
||||||
|
for(i=0; i<BUCKETS_PER_CLUSTER; i++) {
|
||||||
|
if(strcmp(cl->bucket[i], bucketName) == 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int couchbase_operation(struct cbop_s *cbop)
|
||||||
|
{
|
||||||
|
// TODO: check if bucket index in range
|
||||||
|
if(active_instance[cbop->bucket] == NULL) {
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: No active instance for bucket: %d", cbop->bucket);
|
||||||
|
return CB_ERR_NOINSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(cbop->operation) {
|
||||||
|
case CB_GET:
|
||||||
|
return cb_get(cbop);
|
||||||
|
break;
|
||||||
|
case CB_STORE:
|
||||||
|
return cb_store(cbop);
|
||||||
|
break;
|
||||||
|
case CB_REMOVE:
|
||||||
|
return cb_remove(cbop);
|
||||||
|
break;
|
||||||
|
case CB_ARITH:
|
||||||
|
return cb_arithmetic(cbop);
|
||||||
|
break;
|
||||||
|
case CB_VIEW:
|
||||||
|
return cb_view(cbop);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
hm_log(LOG_ERR, cb_log, "{Couchbase}: Operation not supported: %d", cbop->operation);
|
||||||
|
return CB_ERR_OPNOT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void couchbase_deinit()
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
//lcb_t instance;
|
||||||
|
struct cluster_s *cl;
|
||||||
|
const void *cookie;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_GROUPS; i++) {
|
||||||
|
if(groups[i]) {
|
||||||
|
hm_pfree(cd->pool, groups[i]->host);
|
||||||
|
hm_pfree(cd->pool, groups[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hm_pfree(cd->pool, groups); /**< groups */
|
||||||
|
hm_pfree(cd->pool, active_instance); /**< active instances */
|
||||||
|
|
||||||
|
for(i = 0; i < HOSTS; i++) {
|
||||||
|
cl = cd->src[i]->data;
|
||||||
|
|
||||||
|
for(j = 0; j < BUCKETS_PER_CLUSTER; j++) {
|
||||||
|
hm_pfree(cd->pool, cl->bucket[j]);
|
||||||
|
hm_pfree(cd->pool, cl->passwd[j]);
|
||||||
|
if(cl->instance[j]) {
|
||||||
|
cookie = lcb_get_cookie(cl->instance[j]);
|
||||||
|
lcb_destroy_async(cl->instance[j], cookie);
|
||||||
|
//lcb_destroy_io_ops(((struct instance_s *)cookie)->ioops);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hm_pfree(cd->pool, cl->bucket);
|
||||||
|
hm_pfree(cd->pool, cl->passwd);
|
||||||
|
hm_pfree(cd->pool, cl->instance);
|
||||||
|
hm_pfree(cd->pool, cl);
|
||||||
|
}
|
||||||
|
|
||||||
|
connector_free(cd);
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <stdio.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
|
||||||
|
struct ht_s **ht_init(struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
struct ht_s **ht;
|
||||||
|
|
||||||
|
ht = hm_palloc(pool, sizeof(void *) * HT_MAX);
|
||||||
|
if(ht == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(ht, 0, sizeof(void *) * HT_MAX);
|
||||||
|
|
||||||
|
return ht;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ht_free(struct ht_s **ht, struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
hm_pfree(pool, ht);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void ht_key(int *dst, const char *key, const int nkey)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < nkey; i++) {
|
||||||
|
*dst += key[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
*dst %= HT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ht_add(struct ht_s **ht, const char *key, const int nkey, const void *value, const int nvalue, const int alloc, struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
struct ht_s *h;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
assert(ht);
|
||||||
|
|
||||||
|
ht_key(&index, key, nkey);
|
||||||
|
|
||||||
|
for(h = ht[index]; h != NULL; h = h->next) {
|
||||||
|
if(nkey == h->nk && memcmp(key, h->k, nkey) == 0) {
|
||||||
|
/** first, free existing value */
|
||||||
|
if(h->flag == HT_ALLOC) {
|
||||||
|
hm_pfree(pool, h->s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** then copy new value */
|
||||||
|
if(alloc == HT_ALLOC) {
|
||||||
|
h->s = hm_palloc(pool, nvalue);
|
||||||
|
if(h->s == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#ifdef POOL_STDLIB
|
||||||
|
memcpy(h->s, value, nvalue);
|
||||||
|
#else
|
||||||
|
hm_memcpy(h->s, value, nvalue, h->s);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
h->s = (void *)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
h->flag = alloc;
|
||||||
|
h->n = nvalue;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h = hm_palloc(pool, sizeof(*h));
|
||||||
|
if(h == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
h->nk = nkey;
|
||||||
|
h->k = hm_palloc(pool, nkey);
|
||||||
|
if(h->k == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
h->n = nvalue;
|
||||||
|
|
||||||
|
/* always allocate a key */
|
||||||
|
#ifdef POOL_STDLIB
|
||||||
|
memcpy(h->k, key, nkey);
|
||||||
|
#else
|
||||||
|
hm_memcpy(h->k, key, nkey, h->k);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(alloc == HT_ALLOC) {
|
||||||
|
h->flag = HT_ALLOC;
|
||||||
|
h->s = hm_palloc(pool, nvalue);
|
||||||
|
if(h->s == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef POOL_STDLIB
|
||||||
|
memcpy(h->s, value, nvalue);
|
||||||
|
#else
|
||||||
|
hm_memcpy(h->s, value, nvalue, h->s);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
h->flag = 0;
|
||||||
|
h->s = (void *)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
h->next = ht[index];
|
||||||
|
ht[index] = h;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ht_rem(struct ht_s **ht, const char *key, const int nkey, struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
struct ht_s *h, *prev = NULL;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
assert(ht);
|
||||||
|
|
||||||
|
ht_key(&index, key, nkey);
|
||||||
|
|
||||||
|
for(h = ht[index], prev = NULL; h != NULL; prev = h, h = h->next) {
|
||||||
|
if(nkey == h->nk && memcmp(h->k, key, nkey) == 0) {
|
||||||
|
if(prev == NULL) {
|
||||||
|
ht[index] = h->next;
|
||||||
|
} else {
|
||||||
|
prev->next = h->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(h->flag == HT_ALLOC) {
|
||||||
|
hm_pfree(pool, h->s);
|
||||||
|
}
|
||||||
|
hm_pfree(pool, h->k);
|
||||||
|
|
||||||
|
hm_pfree(pool, h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ht_s *ht_get(struct ht_s **ht, const char *key, const int nkey)
|
||||||
|
{
|
||||||
|
struct ht_s *h;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
assert(ht);
|
||||||
|
|
||||||
|
ht_key(&index, key, nkey);
|
||||||
|
|
||||||
|
if(ht[index]) {
|
||||||
|
/** fast access - only one key exists under ht index */
|
||||||
|
if(ht[index] && ht[index]->next == NULL) {
|
||||||
|
return ht[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** otherwise traverse compare against all existing keys */
|
||||||
|
for(h = ht[index]; h != NULL; h = h->next) {
|
||||||
|
if(h->nk == nkey && memcmp(h->k, key, nkey) == 0) {
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ht_dump_index(struct ht_s **ht, const char *key, const int nkey)
|
||||||
|
{
|
||||||
|
struct ht_s *h;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
assert(ht);
|
||||||
|
|
||||||
|
ht_key(&index, key, nkey);
|
||||||
|
|
||||||
|
for(h = ht[index]; h != NULL; h = h->next) {
|
||||||
|
printf("index [%d] with key [%.*s], value [%.*s]\n", index, h->nk, h->k, h->n, h->s);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 HMCLIENT_H_
|
||||||
|
#define HMCLIENT_H_
|
||||||
|
|
||||||
|
#define hm_send(c, conn_buf, conn_len)\
|
||||||
|
/** Only respond if client is still active */\
|
||||||
|
if(c) {\
|
||||||
|
rb_send_init(&c->rb, (char *)conn_buf, conn_len, c->pool);\
|
||||||
|
assert(c->loop);\
|
||||||
|
ev_io_start(c->loop, &c->write);\
|
||||||
|
}
|
||||||
|
|
||||||
|
struct conn_client_s;
|
||||||
|
|
||||||
|
enum clerr_e {
|
||||||
|
CL_NOERROR = 1,
|
||||||
|
CL_HANGTIMEOUT_ERR,
|
||||||
|
CL_WANTSHUTDOWN_ERR,
|
||||||
|
CL_READRBFULL_ERR,
|
||||||
|
CL_READZERO_ERR,
|
||||||
|
CL_READ_ERR,
|
||||||
|
CL_WRITE_ERR,
|
||||||
|
CL_BUFFERFULL_ERR,
|
||||||
|
CL_PACKETLEN_ERR,
|
||||||
|
CL_PACKETEXPECT_ERR,
|
||||||
|
CL_SERVERSHUTDOWN_ERR,
|
||||||
|
CL_SOCKET_ERR
|
||||||
|
};
|
||||||
|
|
||||||
|
struct conn_client_holder_s {
|
||||||
|
int signal_shutdown; ///< signal from client struct if it's already gone
|
||||||
|
struct conn_client_s *client; ///< actual client
|
||||||
|
struct conn_client_holder_s *next; ///< next client
|
||||||
|
};
|
||||||
|
|
||||||
|
struct conn_server_s {
|
||||||
|
struct ev_loop *loop; /**< An external event loop. */
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
struct hm_log_s *log;
|
||||||
|
|
||||||
|
struct conn_client_holder_s *clients_head;
|
||||||
|
int clients;
|
||||||
|
|
||||||
|
struct ev_io listener;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
const char *host;
|
||||||
|
const char *port;
|
||||||
|
|
||||||
|
void (*recv)(struct conn_client_s *data, const char *buf, const int len);
|
||||||
|
void (*client_dc)(void *data, const char *foreign_client_index, const char *hbs_id);
|
||||||
|
void (*shutdown)();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct watcher_s {
|
||||||
|
struct conn_client_s *p1;
|
||||||
|
struct conn_client_s *p2;
|
||||||
|
int counter;
|
||||||
|
int target;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct player_deck_s {
|
||||||
|
char code[16];
|
||||||
|
int count;
|
||||||
|
struct player_deck_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct conn_client_s {
|
||||||
|
struct ev_loop *loop;
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
struct hm_log_s *log;
|
||||||
|
|
||||||
|
struct ev_io read;
|
||||||
|
struct ev_io write;
|
||||||
|
struct ev_timer hang_timer;
|
||||||
|
|
||||||
|
int hang_timer_enabled; ///< TODO: move this to flag
|
||||||
|
int monitor; ///< TODO: move this to flag
|
||||||
|
|
||||||
|
unsigned long long logs; /**< log sequence number */
|
||||||
|
|
||||||
|
int fd;
|
||||||
|
int *shutdown_signal_holder;
|
||||||
|
|
||||||
|
int want_shutdown;
|
||||||
|
int type;
|
||||||
|
|
||||||
|
struct rb_s rb;
|
||||||
|
|
||||||
|
char net_buf[RB_SLOT_SIZE];
|
||||||
|
int net_nbuf;
|
||||||
|
int net_expect;
|
||||||
|
|
||||||
|
char client_index[32];
|
||||||
|
char foreign_client_index[32];
|
||||||
|
|
||||||
|
char ip[64];
|
||||||
|
int nip;
|
||||||
|
int port;
|
||||||
|
|
||||||
|
char date[32];
|
||||||
|
|
||||||
|
void (*recv)(struct conn_client_s *client);
|
||||||
|
void (*error_callback)(struct conn_client_s *client, enum clerr_e error);
|
||||||
|
void (*client_dc)(void *data, const char *foregin_client_index, const char *hbs_id);
|
||||||
|
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
struct conn_server_s *parent;
|
||||||
|
struct conn_client_holder_s *holder;
|
||||||
|
|
||||||
|
char hbs_id[16];
|
||||||
|
#ifdef HM_GAMESERVER
|
||||||
|
struct player_deck_s *cards;
|
||||||
|
int ncards;
|
||||||
|
char hero[16];
|
||||||
|
char hp[16];
|
||||||
|
#elif defined HM_LOBBYSERVER
|
||||||
|
char token[32];
|
||||||
|
int ntoken;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
char user[32];
|
||||||
|
char pass[32];
|
||||||
|
char secret[32];
|
||||||
|
} login;
|
||||||
|
|
||||||
|
int skip;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ht_s **async_clients; // ht of async clients
|
||||||
|
|
||||||
|
int async_shutdown_client(struct conn_client_s *c);
|
||||||
|
void shutdown_server(struct conn_server_s *cs);
|
||||||
|
int connector_server(struct conn_server_s *cs);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 CONNECTOR_H_
|
||||||
|
#define CONNECTOR_H_
|
||||||
|
|
||||||
|
#define CONN_F_CONNECTED 0x1 /**< connected */
|
||||||
|
#define CONN_F_FDOPEN 0x2 /**< keep FD open */
|
||||||
|
#define CONN_F_SINGLECHECK 0x4 /**< interrupt watcher when single client connection est */
|
||||||
|
#define CONN_F_COUCHBASE 0x8 /**< couchbase connection */
|
||||||
|
|
||||||
|
struct conn_data_s;
|
||||||
|
typedef void (*conn_cb_t)(struct conn_data_s *c);
|
||||||
|
|
||||||
|
struct conn_node_s {
|
||||||
|
struct conn_data_s *parent;
|
||||||
|
int group; /**< Group ID */
|
||||||
|
char host[128]; /**< Hostname that must be recognized by inet_addr */
|
||||||
|
int port; /**< Port number */
|
||||||
|
|
||||||
|
int fd; /**< File descriptor */
|
||||||
|
|
||||||
|
unsigned int status; /**< Hostname:port's flag status */
|
||||||
|
|
||||||
|
struct ev_io io; /**< Event that is pushed to an external event loop. */
|
||||||
|
struct ev_timer timer; /**< Timer which stops 'io'. */
|
||||||
|
|
||||||
|
unsigned long long logs;
|
||||||
|
|
||||||
|
void *data; /**< Passed data */
|
||||||
|
|
||||||
|
struct hm_log_s *log;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct conn_data_s {
|
||||||
|
struct ev_loop *loop; /**< An external event loop. */
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
struct hm_log_s *log;
|
||||||
|
|
||||||
|
unsigned long long logs;
|
||||||
|
|
||||||
|
struct conn_node_s **src; /**< An array of conn_node_s to be watched. */
|
||||||
|
int size; /**< Number of connectors to watch. */
|
||||||
|
int established;
|
||||||
|
conn_cb_t callback; /**< Callback function to call when watcher finishes all jobs. */
|
||||||
|
struct ev_timer timer; /**< Timer which finishes all jobs and invokes callback. */
|
||||||
|
float exptime; /**< Expiration time which terminates all jobs */
|
||||||
|
float timeout; /**< Timeout for specific host */
|
||||||
|
};
|
||||||
|
|
||||||
|
int connector(struct conn_data_s *c);
|
||||||
|
void connector_fd_close(int fd);
|
||||||
|
void connector_free(struct conn_data_s *c);
|
||||||
|
int setkeepalive(int fd) ;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 HASHTABLE_H_
|
||||||
|
#define HASHTABLE_H_
|
||||||
|
|
||||||
|
#define HT_MAX (1<<12)
|
||||||
|
#define HT_ALLOC 0x1
|
||||||
|
|
||||||
|
#define HT_ADD(ht, key, nkey, value, nvalue, pool) ht_add(ht, key, nkey, value, nvalue, HT_ALLOC, pool)
|
||||||
|
#define HT_ADD_WA(ht, key, nkey, value, nvalue, pool) ht_add(ht, key, nkey, value, nvalue, 0, pool)
|
||||||
|
#define HT_REM(ht, key, nkey, pool) ht_rem(ht, key, nkey, pool)
|
||||||
|
|
||||||
|
#define ht_item_clear(pool, dst)\
|
||||||
|
if(dst && dst->n > 0) {\
|
||||||
|
hm_pfree(pool, dst->s);\
|
||||||
|
dst->s = NULL;\
|
||||||
|
dst->n = 0;\
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ht_s {
|
||||||
|
char *k;
|
||||||
|
int nk;
|
||||||
|
char *s; ///< value
|
||||||
|
int n; ///< nvalue
|
||||||
|
unsigned int flag;
|
||||||
|
struct ht_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ht_s **ht_init(struct hm_pool_s *pool);
|
||||||
|
void ht_free(struct ht_s **ht, struct hm_pool_s *pool);
|
||||||
|
int ht_add(struct ht_s **ht, const char *key, const int nkey, const void *value, const int nvalue, const int alloc, struct hm_pool_s *pool);
|
||||||
|
int ht_rem(struct ht_s **ht, const char *key, const int nkey, struct hm_pool_s *pool);
|
||||||
|
struct ht_s *ht_get(struct ht_s **ht, const char *key, const int nkey);
|
||||||
|
void ht_dump_index(struct ht_s **ht, const char *key, const int nkey);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 HMBASE_H_
|
||||||
|
#define HMBASE_H_
|
||||||
|
|
||||||
|
#include <ev.h>
|
||||||
|
|
||||||
|
#include <utils.h>
|
||||||
|
#include <log.h>
|
||||||
|
#include <pool.h>
|
||||||
|
#include <hashtable.h>
|
||||||
|
#include <rb.h>
|
||||||
|
#include <hmcouchbase.h>
|
||||||
|
#include <connector.h>
|
||||||
|
#include <async_client.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 HMCOUCHBASE_H_
|
||||||
|
#define HMCOUCHBASE_H_
|
||||||
|
|
||||||
|
#include <libcouchbase/views.h>
|
||||||
|
|
||||||
|
#define CB_ERR_OK 0x0 /**< No error */
|
||||||
|
#define CB_ERR_LCBCREATEIO 0x1 /**< Failed to lcb_create_io_ops() */
|
||||||
|
#define CB_ERR_LCBCREATE 0x2 /**< Failed to lcb_create() */
|
||||||
|
#define CB_ERR_LCBCONNECT 0x3 /**< Failed to lcb_connect() */
|
||||||
|
#define CB_ERR_NOINSTANCE 0x4 /**< No active instance found */
|
||||||
|
#define CB_ERR_NOACTIVE 0x5 /**< Instance is not active */
|
||||||
|
#define CB_ERR_OPNOT 0x6 /**< Operation not supporeted */
|
||||||
|
#define CB_ERR_OPERR 0x7 /**< Operation error */
|
||||||
|
|
||||||
|
#define CB_QUERY_VER 0
|
||||||
|
|
||||||
|
#define CBVQ(m) cbop->u.v.q.m // couchbase view query
|
||||||
|
#define CBSQ(m) cbop->u.s.q.v.v0.m // couchbase store query
|
||||||
|
#define CBRQ(m) cbop->u.r.q.v.v0.m // couchbase remove query
|
||||||
|
#define CBGQ(m) cbop->u.g.q.v.v0.m // couchbase get query
|
||||||
|
#define CBGR(m) cbop->u.g.r->v.v0.m // CouchBase Get Reply
|
||||||
|
#define CBRR(m) cbop->u.r.r->v.v0.m // couchbase remove reply
|
||||||
|
#define CBSR(m) cbop->u.s.r->v.v0.m // couchbase store reply
|
||||||
|
#define CBAQ(m) cbop->u.a.q.v.v0.m // couchbase arithmetic query
|
||||||
|
#define CBAR(m) cbop->u.a.r->v.v0.m // couchbase arithmetic reply
|
||||||
|
|
||||||
|
/**< CBSQ_V0 - CouchBase Store Query V0
|
||||||
|
* bucket, operation, key, nkey, bytes, nbytes, callback, cas, exptime, datatype, flags
|
||||||
|
* 'struct cbop_s *cbop' must exist within context
|
||||||
|
*/
|
||||||
|
#define CBSQ_V0(b, o, k, nk, bt, nb, f, c, e, d, flag)\
|
||||||
|
cbop->bucket = b;\
|
||||||
|
cbop->operation = CB_STORE;\
|
||||||
|
cbop->u.s.q.version = CB_QUERY_VER;\
|
||||||
|
CBSQ(operation) = o;\
|
||||||
|
CBSQ(key) = k;\
|
||||||
|
CBSQ(nkey) = nk;\
|
||||||
|
CBSQ(bytes) = bt;\
|
||||||
|
CBSQ(nbytes) = nb;\
|
||||||
|
CBSQ(cas) = c;\
|
||||||
|
CBSQ(exptime) = e;\
|
||||||
|
CBSQ(datatype) = d;\
|
||||||
|
CBSQ(flags) = flag;\
|
||||||
|
cbop->post = f;\
|
||||||
|
(void)couchbase_operation(cbop);
|
||||||
|
/*if(couchbase_operation(cbop) != CB_ERR_OK) { */
|
||||||
|
|
||||||
|
|
||||||
|
/**< CBGQ_V0 - CouchBase Get Query V0
|
||||||
|
* bucket, key, nkey, callback, exptime, lock
|
||||||
|
* 'struct cbop_s *cbop' must exist within context
|
||||||
|
*/
|
||||||
|
#define CBGQ_V0(b, k, nk, f, e, l)\
|
||||||
|
cbop->bucket = b;\
|
||||||
|
cbop->operation = CB_GET;\
|
||||||
|
cbop->u.g.q.version = CB_QUERY_VER;\
|
||||||
|
CBGQ(key) = k;\
|
||||||
|
CBGQ(nkey) = nk;\
|
||||||
|
CBGQ(exptime) = e;\
|
||||||
|
CBGQ(lock) = l;\
|
||||||
|
cbop->post = f;\
|
||||||
|
(void)couchbase_operation(cbop);
|
||||||
|
/*if(couchbase_operation(cbop) != CB_ERR_OK) { */
|
||||||
|
|
||||||
|
/**< CBRQ_V0 - CouchBase Remove Query V0
|
||||||
|
* bucket, key, nkey, callback, cas
|
||||||
|
* 'struct cbop_s *cbop' must exist within context
|
||||||
|
*/
|
||||||
|
#define CBRQ_V0(b, k, nk, f, c)\
|
||||||
|
cbop->bucket = b;\
|
||||||
|
cbop->operation = CB_REMOVE;\
|
||||||
|
cbop->u.r.q.version = CB_QUERY_VER;\
|
||||||
|
CBRQ(key) = k;\
|
||||||
|
CBRQ(nkey) = nk;\
|
||||||
|
CBRQ(cas) = c;\
|
||||||
|
cbop->post = f;\
|
||||||
|
(void)couchbase_operation(cbop);
|
||||||
|
/*if(couchbase_operation(cbop) != CB_ERR_OK) { */
|
||||||
|
|
||||||
|
/**< CBAQ_V0 - CouchBase Arithmetic Query V0
|
||||||
|
* bucket, key, nkey, callback, create, delta, initial
|
||||||
|
* 'struct cbop_s *cbop' must exist within context
|
||||||
|
*/
|
||||||
|
#define CBAQ_V0(b, k, nk, f, c, d, i)\
|
||||||
|
cbop->bucket = b;\
|
||||||
|
cbop->operation = CB_ARITH;\
|
||||||
|
cbop->u.a.q.version = CB_QUERY_VER;\
|
||||||
|
CBAQ(key) = k;\
|
||||||
|
CBAQ(nkey) = nk;\
|
||||||
|
CBAQ(create) = c;\
|
||||||
|
CBAQ(delta) = d;\
|
||||||
|
CBAQ(initial) = i;\
|
||||||
|
cbop->post = f;\
|
||||||
|
(void)couchbase_operation(cbop);
|
||||||
|
/*if(couchbase_operation(cbop) != CB_ERR_OK) { */
|
||||||
|
|
||||||
|
/**< CBVQ_V0 - CouchBase View Query V0
|
||||||
|
* bucket, cmd, doc, ndoc, view, nview, options, noptions, post, npost, dcm, callback, handle
|
||||||
|
* 'struct cbop_s *cbop' must exist within context
|
||||||
|
*/
|
||||||
|
#define CBVQ_V0(b, c, d, nd, v, nv, o, no, p, np, dcm, f, h)\
|
||||||
|
cbop->bucket = b;\
|
||||||
|
cbop->operation = CB_VIEW;\
|
||||||
|
CBVQ(cmdflags) = c;\
|
||||||
|
CBVQ(ddoc) = d;\
|
||||||
|
CBVQ(nddoc) = nd;\
|
||||||
|
CBVQ(view) = v;\
|
||||||
|
CBVQ(nview) = nv;\
|
||||||
|
CBVQ(optstr) = o;\
|
||||||
|
CBVQ(noptstr) = no;\
|
||||||
|
CBVQ(postdata) = p;\
|
||||||
|
CBVQ(npostdata) = np;\
|
||||||
|
CBVQ(docs_concurrent_max) = dcm;\
|
||||||
|
CBVQ(callback) = f;\
|
||||||
|
CBVQ(handle) = h;\
|
||||||
|
(void)couchbase_operation(cbop);
|
||||||
|
/*if(couchbase_operation(cbop) != CB_ERR_OK) { */
|
||||||
|
|
||||||
|
#define CONNSTR_SIZE 2048
|
||||||
|
#define MAX_GROUPS 16 /**< max couchbase datacenters */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CB_GET = 0x1,
|
||||||
|
CB_STORE = 0x2,
|
||||||
|
CB_REMOVE = 0x3,
|
||||||
|
CB_ARITH = 0x4,
|
||||||
|
CB_VIEW = 0x5
|
||||||
|
} cboperation_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef enum {
|
||||||
|
LCB_ADD = 0x01,
|
||||||
|
LCB_REPLACE = 0x02,
|
||||||
|
LCB_SET = 0x03,
|
||||||
|
LCB_APPEND = 0x04,
|
||||||
|
LCB_PREPEND = 0x05
|
||||||
|
} lcb_storage_t;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
syslog priorities:
|
||||||
|
LOG_EMERG system is unusable
|
||||||
|
LOG_ALERT action must be taken immediately
|
||||||
|
LOG_CRIT critical conditions
|
||||||
|
LOG_ERR error conditions
|
||||||
|
LOG_WARNING warning conditions
|
||||||
|
LOG_NOTICE normal, but significant, condition
|
||||||
|
LOG_INFO informational message
|
||||||
|
LOG_DEBUG debug-level message
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief cbop_s structure is passed to every couchbase request
|
||||||
|
*
|
||||||
|
* User must allocate and deallocate space for this structure.
|
||||||
|
*/
|
||||||
|
struct cbop_s {
|
||||||
|
int bucket; /**< Index of bucket */
|
||||||
|
cboperation_t operation; /**< Couchbase operation, @see cboperation_t */
|
||||||
|
void (*post)(struct cbop_s *cbop);
|
||||||
|
lcb_error_t lcb_error; /**< Libcouchbase error code in case callback function needs it */
|
||||||
|
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
lcb_get_cmd_t q; /**< Query */
|
||||||
|
const lcb_get_resp_t *r; /**< Response */
|
||||||
|
} g; /**< This is a Get procedure definition. */
|
||||||
|
|
||||||
|
struct {
|
||||||
|
lcb_store_cmd_t q; /**< Query */
|
||||||
|
const lcb_store_resp_t *r; /**< Response */
|
||||||
|
} s; /**< This is a Store procedure definition. */
|
||||||
|
|
||||||
|
struct {
|
||||||
|
lcb_remove_cmd_t q; /**< Query */
|
||||||
|
const lcb_remove_resp_t *r; /**< Response */
|
||||||
|
} r; /**< This is a Remove procedure definition. */
|
||||||
|
|
||||||
|
struct {
|
||||||
|
lcb_arithmetic_cmd_t q; /**< Query */
|
||||||
|
const lcb_arithmetic_resp_t *r; /**< Response */
|
||||||
|
} a; /**< This is an Arithmetic procedure definition. */
|
||||||
|
|
||||||
|
struct {
|
||||||
|
lcb_CMDVIEWQUERY q; /**< Query */
|
||||||
|
struct lcb_RESPVIEW_st r; /**< Response */
|
||||||
|
} v; /**< This is a View procedure definition. */
|
||||||
|
} u;
|
||||||
|
|
||||||
|
void *g_child; /** grunt's child */
|
||||||
|
void *data; /**< Some other client's data. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct cluster_s
|
||||||
|
*
|
||||||
|
* Every bucket has its own instance.
|
||||||
|
*/
|
||||||
|
struct cluster_s {
|
||||||
|
char **bucket;
|
||||||
|
char **passwd;
|
||||||
|
lcb_t *instance;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct couchbase_data_s;
|
||||||
|
/**
|
||||||
|
* @brief struct instance_s
|
||||||
|
*
|
||||||
|
* Every cluster has its own group.
|
||||||
|
*/
|
||||||
|
struct instance_s {
|
||||||
|
struct ev_loop *loop;
|
||||||
|
struct hm_log_s *log;
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
char connstr[CONNSTR_SIZE];
|
||||||
|
int status;
|
||||||
|
int group;
|
||||||
|
int index;
|
||||||
|
lcb_io_opt_t ioops;
|
||||||
|
struct instance_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct couchbase_data_s
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct couchbase_data_s {
|
||||||
|
struct ev_loop *loop;
|
||||||
|
struct hm_log_s *log;
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
void (*callback)(struct instance_s *data);
|
||||||
|
|
||||||
|
const char **hosts;
|
||||||
|
const int *hgroups;
|
||||||
|
int nhosts;
|
||||||
|
const char **buckets;
|
||||||
|
const char **bpasswd;
|
||||||
|
int nbuckets;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct connstr_s {
|
||||||
|
int id;
|
||||||
|
char *host;
|
||||||
|
int len;
|
||||||
|
};
|
||||||
|
|
||||||
|
int couchbase_init(struct couchbase_data_s *cbd);
|
||||||
|
int couchbase_bucket_index(const char *bucketName); ///< Returns the bucket index, or -1 if there is no such bucket
|
||||||
|
int couchbase_operation(struct cbop_s *cbop);
|
||||||
|
void couchbase_deinit();
|
||||||
|
extern int couchbase_deinit_async;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 HMLOG_H_
|
||||||
|
#define HMLOG_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
enum errors_e {
|
||||||
|
LOG_EMERG = 0, ///< system is unusable
|
||||||
|
LOG_ALERT, ///< action must be taken immediately
|
||||||
|
LOG_CRIT, ///< critical conditions
|
||||||
|
LOG_ERR, ///< error conditions
|
||||||
|
LOG_WARNING, ///< warning conditions
|
||||||
|
LOG_NOTICE, //< normal, but significant, condition
|
||||||
|
LOG_INFO, //< informational message
|
||||||
|
LOG_DEBUG, ///< debug-level message
|
||||||
|
LOG_MEMORY, ///< memory-level message
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hm_log_s {
|
||||||
|
const char *name;
|
||||||
|
int fd;
|
||||||
|
FILE *file;
|
||||||
|
void *data;
|
||||||
|
int priority;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define hm_log(t, l, fmt...)\
|
||||||
|
hm_log_impl(0, t, l, __FILE__, __LINE__, __FUNCTION__, fmt)
|
||||||
|
|
||||||
|
int hm_log_impl(unsigned long long seq_nb, int priority, struct hm_log_s *log, const char *file, int line, const char *func, const char *fmt, ...) __attribute__ ((format (printf, 7, 8)));
|
||||||
|
int hm_log_open(struct hm_log_s *l, const char *filename, const int priority);
|
||||||
|
int hm_log_close(struct hm_log_s *l);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 HMPOOL_H_
|
||||||
|
#define HMPOOL_H_
|
||||||
|
|
||||||
|
#define POOL_DEBUG
|
||||||
|
#define POOL_STDLIB
|
||||||
|
|
||||||
|
struct pool_bucket_s {
|
||||||
|
void *memory_region;
|
||||||
|
void *nodes;
|
||||||
|
struct pool_bucket_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hm_pool_s {
|
||||||
|
int size;
|
||||||
|
int used;
|
||||||
|
struct hm_log_s *log;
|
||||||
|
struct pool_node_s *freenode;
|
||||||
|
struct pool_bucket_s *buckets;
|
||||||
|
struct hm_pool_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pool_node_s {
|
||||||
|
void *ptr;
|
||||||
|
int size;
|
||||||
|
int realsize;
|
||||||
|
int used;
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
struct pool_node_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hm_pool_s *hm_create_pool();
|
||||||
|
void *hm_palloc(struct hm_pool_s *pool, int size);
|
||||||
|
void *hm_prealloc(struct hm_pool_s *pool, void *ptr, const int size);
|
||||||
|
void *hm_memcpy(void *dst, const void *src, const int n, void *start);
|
||||||
|
int hm_pfree(struct hm_pool_s *pool, void *ptr);
|
||||||
|
int hm_destroy_pool(struct hm_pool_s *pool);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 RB_H
|
||||||
|
#define RB_H
|
||||||
|
|
||||||
|
#define RB_SLOT_SIZE (16 * 1024)
|
||||||
|
|
||||||
|
|
||||||
|
struct rb_slot_s {
|
||||||
|
void *buf;
|
||||||
|
int len;
|
||||||
|
int sent;
|
||||||
|
struct rb_slot_s *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct rb_s {
|
||||||
|
struct {
|
||||||
|
char slot[RB_SLOT_SIZE];
|
||||||
|
int len;
|
||||||
|
} recv;
|
||||||
|
|
||||||
|
struct rb_slot_s *send, *tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
char *rb_send_next(struct rb_s *rb, int *size);
|
||||||
|
void rb_send_skip(struct rb_s *rb, int offset);
|
||||||
|
int rb_send_is_empty(struct rb_s *rb);
|
||||||
|
void rb_send_pop(struct rb_s *rb, struct hm_pool_s *pool);
|
||||||
|
int rb_send_init(struct rb_s *rb, char *buf, const int len, struct hm_pool_s *pool);
|
||||||
|
char *rb_recv_ptr(struct rb_s *rb, int *used);
|
||||||
|
void rb_recv_append(struct rb_s *rb, const int len);
|
||||||
|
char *rb_recv_read(struct rb_s *rb, int *size);
|
||||||
|
void rb_recv_pop(struct rb_s *rb);
|
||||||
|
int rb_recv_is_full(struct rb_s *rb);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 UTILS_H_
|
||||||
|
#define UTILS_H_
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#define EQFLAG(d, f)\
|
||||||
|
((d & f) == f)
|
||||||
|
|
||||||
|
/** N memory compare */
|
||||||
|
#define nmc(dst, ndst, src, nsrc) (ndst == nsrc && memcmp(dst, src, ndst) == 0)
|
||||||
|
|
||||||
|
inline static void to_lower(char *bytes, const int nbytes)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < nbytes; i++) {
|
||||||
|
if(bytes[i] >= 65 && bytes[i] <= 90) {
|
||||||
|
bytes[i] += 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void mac_tonum(char *dst, const int ndst, char *src, const int nsrc)
|
||||||
|
{
|
||||||
|
char *s, *e;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(nsrc != 17 || ndst < 17) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0, s = src, e = src + nsrc; s < e; s++) {
|
||||||
|
if(*s == ':' && s - 2 >= src) {
|
||||||
|
memcpy(&dst[i], s - 2, 2);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
else if(i == 10 && s + 2 <= e) {
|
||||||
|
memcpy(&dst[i], s, 2);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst[i] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void replace_space(char *dst, const int ndst, const char src)
|
||||||
|
{
|
||||||
|
char *s, *e;
|
||||||
|
|
||||||
|
for(s = dst, e = dst + ndst; s < e; s++) {
|
||||||
|
if(*s == ' ') {
|
||||||
|
*s = src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void num_tomac(char *dst, const int ndst, char *src, const int nsrc)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
char *ds, *de;
|
||||||
|
char *ss, *se;
|
||||||
|
|
||||||
|
// 17 + 1 term
|
||||||
|
if(ndst < 18) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0,
|
||||||
|
ss = src, se = src + nsrc,
|
||||||
|
ds = dst, de = dst + ndst;
|
||||||
|
(ss < se && (ds + i)< de);
|
||||||
|
/* void */) {
|
||||||
|
memcpy(&dst[i], ss, 2);
|
||||||
|
i += 2;
|
||||||
|
dst[i++] = ':';
|
||||||
|
ss += 2;
|
||||||
|
if(i >= 16) {
|
||||||
|
dst[--i] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static int is_valid_mac(char *buf, const int len)
|
||||||
|
{
|
||||||
|
char *s, *e;
|
||||||
|
|
||||||
|
if(len < 17) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** buf must point to first char of mac */
|
||||||
|
for(s = buf, e = buf + len; s < e; s++) {
|
||||||
|
/** we're looking for a mac address xx:xx:xx:xx:xx:xx
|
||||||
|
* ( 1 - : ) || ( A - Z ) || ( a - z )
|
||||||
|
*/
|
||||||
|
if(!((*s >= 48 && *s <= 58) || (*s >= 65 && *s <= 90) || (*s >= 97 && *s <= 122))) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(s - buf == 16) {
|
||||||
|
return (s - buf) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static int random_number(int max)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
srand(ts.tv_nsec);
|
||||||
|
|
||||||
|
return (rand() % max);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
|
||||||
|
int hm_log_impl(unsigned long long seq_nb, int priority, struct hm_log_s *log, const char *file, const int line, const char *func, const char *msg, ...)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
char out[8192], buf[128];
|
||||||
|
time_t s;
|
||||||
|
struct timespec spec;
|
||||||
|
long long ms;
|
||||||
|
struct tm ts;
|
||||||
|
|
||||||
|
assert(log);
|
||||||
|
|
||||||
|
/** only display messages user asked for */
|
||||||
|
if(priority > log->priority) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if(log->fd == STDERR_FILENO)
|
||||||
|
{
|
||||||
|
const char *colour;
|
||||||
|
switch(priority) {
|
||||||
|
case LOG_EMERG: //< system is unusable
|
||||||
|
colour = "(%llu) \33[1;31;41mLOG_EMERG\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_ALERT: //< action must be taken immediately
|
||||||
|
colour = "(%llu) \33[1;33;41mLOG_ALERT\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_CRIT: //< critical conditions
|
||||||
|
colour = "(%llu) \33[1;31;40mLOG_CRIT\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_ERR: //< error conditions
|
||||||
|
colour = "(%llu) \33[1;34;41mLOG_ERR\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_WARNING: //< warning conditions
|
||||||
|
colour = "(%llu) \33[1;37;43mLOG_WARNING\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_NOTICE: //< normal, but significant, condition
|
||||||
|
colour = "(%llu) \33[1;34;47mLOG_NOTICE\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_INFO: //< informational message
|
||||||
|
colour = "(%llu) \33[1;37;42mLOG_INFO\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_DEBUG: //< debug-level message
|
||||||
|
colour = "(%llu) \33[1;32;40mLOG_DEBUG\33[m";
|
||||||
|
break;
|
||||||
|
case LOG_MEMORY: //< memory message
|
||||||
|
colour = "(%llu) \33[1;35;34mLOG_MEMORY\33[m";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
colour = NULL;
|
||||||
|
}
|
||||||
|
if(colour) {
|
||||||
|
len += snprintf(out, sizeof(out), colour, seq_nb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &spec);
|
||||||
|
s = spec.tv_sec;
|
||||||
|
ms = round(spec.tv_nsec / 1.0e6);
|
||||||
|
|
||||||
|
ts = *localtime(&s);
|
||||||
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ts);
|
||||||
|
|
||||||
|
len += snprintf(out + len, sizeof(out) - len, "[%s.%03lld] ", buf, ms);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
len += vsnprintf(out+len, 3*sizeof(out)/4-len, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
if(len >= 3*sizeof(out)/4) {
|
||||||
|
len += snprintf(out + len, sizeof(out) - len, "...");
|
||||||
|
}
|
||||||
|
|
||||||
|
len += snprintf(out+len, sizeof(out)-len, ", %s:%d(%s)\n", file, line, func);
|
||||||
|
|
||||||
|
ssize_t nwritten = write(log->fd, out, len);
|
||||||
|
return (nwritten == len) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int hm_log_open(struct hm_log_s *l, const char *filename, const int priority)
|
||||||
|
{
|
||||||
|
if(filename != NULL) {
|
||||||
|
l->file = fopen(filename, "a");
|
||||||
|
if(l->file == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
l->fd = fileno(l->file);
|
||||||
|
} else {
|
||||||
|
l->file = stderr;
|
||||||
|
l->fd = STDERR_FILENO;
|
||||||
|
}
|
||||||
|
|
||||||
|
l->priority = priority;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int hm_log_close(struct hm_log_s *l)
|
||||||
|
{
|
||||||
|
if(l->file && l->file != stderr) {
|
||||||
|
fclose(l->file);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,368 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
|
||||||
|
#define BUCKET_MAX 2
|
||||||
|
#define ROUND16(dst) (((dst) + 15) & ~15)
|
||||||
|
|
||||||
|
#define get_meta(m_ptr) (*(struct pool_node_s **)((struct pool_node_s ***)(m_ptr - sizeof(void *))))
|
||||||
|
|
||||||
|
static int pool_create_bucket(struct hm_pool_s *pool);
|
||||||
|
|
||||||
|
int hm_pfree(struct hm_pool_s *pool, void *ptr)
|
||||||
|
{
|
||||||
|
#ifdef POOL_STDLIB
|
||||||
|
free(ptr);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct hm_pool_s *p;
|
||||||
|
struct pool_node_s *node;
|
||||||
|
|
||||||
|
if(ptr == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** get to metadata */
|
||||||
|
node = get_meta(ptr);
|
||||||
|
|
||||||
|
for(p = pool; p != NULL; p = p->next) {
|
||||||
|
if(node && node->used && node->size == p->size) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: old freenode: %p/%d, new freenode: %p/%d from pool:%p/%d", p->freenode, p->freenode->realsize, node, node->realsize, p, p->size);
|
||||||
|
#endif
|
||||||
|
node->used = 0;
|
||||||
|
node->next = p->freenode;
|
||||||
|
p->freenode = node;
|
||||||
|
|
||||||
|
--p->used;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *pool_get_node(struct hm_pool_s *pool, const int realsize)
|
||||||
|
{
|
||||||
|
struct pool_node_s *node = NULL;
|
||||||
|
|
||||||
|
node = pool->freenode;
|
||||||
|
assert(node);
|
||||||
|
pool->freenode = node->next;
|
||||||
|
|
||||||
|
if(node->next == NULL) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "no more freenodes remaining in pool: %p/%d, creating new bucket", pool, pool->size);
|
||||||
|
#endif
|
||||||
|
if(pool_create_bucket(pool) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: returning node: %p/%d, new freenode: %p from pool: %p/%d", node, realsize, pool->freenode, pool, pool->size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** increment used nodes */
|
||||||
|
++pool->used;
|
||||||
|
|
||||||
|
/** real size of block */
|
||||||
|
node->realsize = realsize;
|
||||||
|
|
||||||
|
node->used = 1;
|
||||||
|
|
||||||
|
/** metadata offset */
|
||||||
|
return (node->ptr + sizeof(void *));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** don't do anything but creating a zero valued holder */
|
||||||
|
struct hm_pool_s *hm_create_pool(struct hm_log_s *log)
|
||||||
|
{
|
||||||
|
struct hm_pool_s *pool;
|
||||||
|
|
||||||
|
pool = malloc(sizeof(*pool));
|
||||||
|
|
||||||
|
if(pool == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(pool, 0, sizeof(*pool));
|
||||||
|
pool->log = log;
|
||||||
|
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: pool created %p", pool);
|
||||||
|
#endif
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pool_create_bucket(struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
void *nodes, *region;
|
||||||
|
struct pool_bucket_s *b;
|
||||||
|
struct pool_node_s *node;
|
||||||
|
|
||||||
|
/** holder of buckets */
|
||||||
|
b = malloc(sizeof(*b));
|
||||||
|
|
||||||
|
if(b == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
region = malloc((pool->size + sizeof(void *)) * BUCKET_MAX);
|
||||||
|
|
||||||
|
/** nodes holders */
|
||||||
|
nodes = malloc(BUCKET_MAX * sizeof(struct pool_node_s));
|
||||||
|
|
||||||
|
if(nodes == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->memory_region = region;
|
||||||
|
b->nodes = nodes;
|
||||||
|
|
||||||
|
for(i = 0; BUCKET_MAX > i; i++) {
|
||||||
|
node = (struct pool_node_s *)(nodes + (i * sizeof(struct pool_node_s)));
|
||||||
|
/** node's offset set by i * (metadata + size)*/
|
||||||
|
node->ptr = (void *)(region + i * (sizeof(void *) + pool->size));
|
||||||
|
/** copy metadata to offset + 0 */
|
||||||
|
memcpy(node->ptr, &node, sizeof(node));
|
||||||
|
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "new node: %p in pool: %p old freenode: %p pool size: %d node ptr: %p reg: %p", node, pool, pool->freenode, pool->size, node->ptr, *(void **)node->ptr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(j = 0; j < 32; j++) {
|
||||||
|
printf("%d|", ((char *)(node->ptr))[j]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
node->size = pool->size;
|
||||||
|
node->next = pool->freenode;
|
||||||
|
node->pool = pool;
|
||||||
|
node->realsize = 0;
|
||||||
|
pool->freenode = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->next = pool->buckets;
|
||||||
|
pool->buckets = b;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *hm_memcpy(void *dst, const void *src, const int n, void *start)
|
||||||
|
{
|
||||||
|
int diff;
|
||||||
|
struct pool_node_s *node;
|
||||||
|
|
||||||
|
node = get_meta(start);
|
||||||
|
|
||||||
|
diff = dst - (node->ptr + sizeof(void *));
|
||||||
|
|
||||||
|
//printf("memcpy diff %d\n", node->size);
|
||||||
|
|
||||||
|
if(n + diff > node->size) {
|
||||||
|
hm_log(LOG_ERR, node->pool->log, "{Pool}: illegal memcpy(), overlapping dst of %d with %d bytes", node->size, diff + n);
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
return memcpy(dst, src, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct hm_pool_s *pool_create_append(struct hm_pool_s *pool, const int size)
|
||||||
|
{
|
||||||
|
struct hm_pool_s *p, *tp;
|
||||||
|
|
||||||
|
p = malloc(sizeof(*p));
|
||||||
|
|
||||||
|
if(p == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** set pool size */
|
||||||
|
p->size = size;
|
||||||
|
p->next = NULL;
|
||||||
|
p->freenode = NULL;
|
||||||
|
p->buckets = NULL;
|
||||||
|
p->used = 0;
|
||||||
|
p->log = pool->log;
|
||||||
|
|
||||||
|
if(pool_create_bucket(p) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(tp = pool; tp != NULL; tp = tp->next) {
|
||||||
|
if(tp->next == NULL) {
|
||||||
|
tp->next = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The realloc() function changes the size of the memory block pointed to by ptr to size bytes. The contents
|
||||||
|
will be unchanged in the range from the start of the region up to the minimum of the old and new sizes. If
|
||||||
|
the new size is larger than the old size, the added memory will not be initialized. If ptr is NULL, then the
|
||||||
|
call is equivalent to malloc(size), for all values of size; if size is equal to zero, and ptr is not NULL,
|
||||||
|
then the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call
|
||||||
|
to malloc(), calloc() or realloc(). If the area pointed to was moved, a free(ptr) is done.
|
||||||
|
*/
|
||||||
|
void *hm_prealloc(struct hm_pool_s *pool, void *ptr, const int size)
|
||||||
|
{
|
||||||
|
#ifdef POOL_STDLIB
|
||||||
|
return realloc(ptr, size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct pool_node_s *node = NULL;
|
||||||
|
void *dst;
|
||||||
|
|
||||||
|
if(ptr != NULL) {
|
||||||
|
node = get_meta(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ptr == NULL && size == 0) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: doing nothing");
|
||||||
|
#endif
|
||||||
|
/** do nothing */
|
||||||
|
return NULL;
|
||||||
|
} else if(ptr == NULL && size != 0) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: malloc() size: %d", size);
|
||||||
|
#endif
|
||||||
|
/** malloc() */
|
||||||
|
return hm_palloc(pool, size);
|
||||||
|
} else if(ptr != NULL && size == 0) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: free() size: %d", size);
|
||||||
|
#endif
|
||||||
|
/** free() */
|
||||||
|
if(hm_pfree(pool, ptr) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
} else if(ptr != NULL && node != NULL && node->size == size) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: status quo for size: %d", size);
|
||||||
|
#endif
|
||||||
|
/** nothing needs to be changed - return exactly the same pointer */
|
||||||
|
return ptr;
|
||||||
|
} else if(ptr != NULL && size > 0 && node != NULL && node->size != size) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: realloc for old size: %d new size: %d", node->size, size);
|
||||||
|
#endif
|
||||||
|
/** realloc() */
|
||||||
|
|
||||||
|
/** first allocate new dst */
|
||||||
|
dst = hm_palloc(pool, size);
|
||||||
|
|
||||||
|
if(dst == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** copy src to dst */
|
||||||
|
if(node->realsize <= size) {
|
||||||
|
memcpy(dst, ptr, node->realsize);
|
||||||
|
} else {
|
||||||
|
memcpy(dst, ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** free src */
|
||||||
|
hm_pfree(pool, ptr);
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *hm_palloc(struct hm_pool_s *pool, int size)
|
||||||
|
{
|
||||||
|
#ifdef POOL_STDLIB
|
||||||
|
return malloc(size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct hm_pool_s *p;
|
||||||
|
|
||||||
|
assert(pool);
|
||||||
|
|
||||||
|
for(p = pool; p != NULL; p = p->next) {
|
||||||
|
/** do we match an existing pool */
|
||||||
|
if(ROUND16(size) == p->size) {
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: found existing pool: %p/%d", p, p->size);
|
||||||
|
#endif
|
||||||
|
return pool_get_node(p, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p = pool_create_append(pool, ROUND16(size));
|
||||||
|
|
||||||
|
if(p == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef POOL_DEBUG
|
||||||
|
hm_log(LOG_MEMORY, pool->log, "{Pool}: creating new pool with parent pool: %p/%d", p, p->size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return pool_get_node(p, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int hm_destroy_pool(struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
struct hm_pool_s *p, *pd;
|
||||||
|
struct pool_bucket_s *b, *bd;
|
||||||
|
|
||||||
|
for(p = pool; p != NULL; ) {
|
||||||
|
for(b = p->buckets; b != NULL; ) {
|
||||||
|
free(b->memory_region);
|
||||||
|
free(b->nodes);
|
||||||
|
|
||||||
|
bd = b;
|
||||||
|
b = b->next;
|
||||||
|
free(bd);
|
||||||
|
}
|
||||||
|
pd = p;
|
||||||
|
p = p->next;
|
||||||
|
free(pd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pool_info(struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
struct hm_pool_s *p;
|
||||||
|
|
||||||
|
for(p = pool; p != NULL; p = p->next) {
|
||||||
|
printf("pool size: %d used: %d\n", p->size, p->used);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
hm_base - hearthmod base library
|
||||||
|
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 <assert.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
#include <hmbase.h>
|
||||||
|
|
||||||
|
/** Send functions */
|
||||||
|
char *rb_send_next(struct rb_s *rb, int *size)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
|
||||||
|
if(rb->send == NULL) {
|
||||||
|
*size = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*size = rb->send->len - rb->send->sent;
|
||||||
|
// test
|
||||||
|
/*
|
||||||
|
if(*size >= 10) {
|
||||||
|
*size = 10;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return (char *)(rb->send->buf + rb->send->sent);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rb_next(struct rb_s *rb)
|
||||||
|
{
|
||||||
|
struct rb_slot_s *next;
|
||||||
|
|
||||||
|
if(rb && rb->send && rb->send->sent == rb->send->len) {
|
||||||
|
next = rb->send->next;
|
||||||
|
free(rb->send->buf);
|
||||||
|
free(rb->send);
|
||||||
|
rb->send = next;
|
||||||
|
if(rb->send == NULL) {
|
||||||
|
rb->tail = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void rb_send_skip(struct rb_s *rb, int offset)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
assert(rb->send);
|
||||||
|
rb->send->sent += offset;
|
||||||
|
|
||||||
|
rb_next(rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rb_send_is_empty(struct rb_s *rb)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
return (rb->send == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rb_send_pop(struct rb_s *rb, struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
rb_next(rb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rb_send_init(struct rb_s *rb, char *buf, const int len, struct hm_pool_s *pool)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
struct rb_slot_s *slot;
|
||||||
|
|
||||||
|
slot = malloc(sizeof(*slot));
|
||||||
|
if(slot == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
slot->buf = malloc(len);
|
||||||
|
if(slot->buf == NULL) {
|
||||||
|
free(slot);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(slot->buf, buf, len);
|
||||||
|
slot->len = len;
|
||||||
|
slot->sent = 0;
|
||||||
|
slot->next = NULL;
|
||||||
|
|
||||||
|
if(rb->send == NULL && rb->tail == NULL) {
|
||||||
|
//printf("added to head send init\n");
|
||||||
|
rb->send = rb->tail = slot;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//printf("added to tail send init\n");
|
||||||
|
assert(rb->tail);
|
||||||
|
rb->tail->next = slot;
|
||||||
|
rb->tail = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Receive functions */
|
||||||
|
char *rb_recv_ptr(struct rb_s *rb, int *used)
|
||||||
|
{
|
||||||
|
assert(rb && used);
|
||||||
|
*used = rb->recv.len;
|
||||||
|
return (rb->recv.slot + rb->recv.len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rb_recv_append(struct rb_s *rb, const int len)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
rb->recv.len += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *rb_recv_read(struct rb_s *rb, int *size)
|
||||||
|
{
|
||||||
|
assert(rb && size);
|
||||||
|
*size = rb->recv.len;
|
||||||
|
return rb->recv.slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rb_recv_pop(struct rb_s *rb)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
rb->recv.len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rb_recv_is_full(struct rb_s *rb)
|
||||||
|
{
|
||||||
|
assert(rb);
|
||||||
|
return (rb->recv.len >= RB_SLOT_SIZE);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# hm_database
|
||||||
|
hearthmod database dump
|
||||||
|
|
||||||
|
# This is not a standalone project!
|
||||||
|
|
||||||
|
[hm_database](https://github.com/farb3yonddriv3n/hm_database) is part of [hearthmod software stack](https://github.com/hearthmod/hearthmod)
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/opt/couchbase/bin/cbbackup http://localhost:8091 `pwd`/hbs/ \
|
||||||
|
-u $1 -p $2 -b hbs
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[{"controllers": {"compact": "/pools/default/buckets/hbs/ddocs/_design%2Fdev_result/controller/compactView", "setUpdateMinChanges": "/pools/default/buckets/hbs/ddocs/_design%2Fdev_result/controller/setUpdateMinChanges"}, "doc": {"json": {"views": {"result": {"map": "function (doc, meta) {\n if(doc.w && doc.l) {\n \temit(meta.id, doc);\n }\n}"}}}, "meta": {"rev": "4-1816919e", "id": "_design/dev_result"}}}]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"metadata": [{"indexerId": "7a:b4:24:44:47:40:57:8e"}]}
|
||||||
BIN
Binary file not shown.
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
|||||||
|
{"pred": []}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"386": 3, "147": 2, "39": 3, "620": 2, "20": 68, "126": 2, "669": 3, "465": 2, "953": 2, "277": 626, "779": 147, "902": 2, "182": 6, "674": 2, "62": 2, "321": 1861, "135": 428, "127": 3, "297": 2, "522": 736}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"386": [0, 3], "147": [0, 2], "39": [0, 3], "620": [0, 2], "20": [0, 68], "126": [0, 2], "669": [0, 3], "465": [0, 2], "953": [0, 2], "277": [0, 626], "779": [0, 147], "902": [0, 2], "182": [0, 6], "674": [0, 2], "62": [0, 2], "321": [0, 1861], "135": [0, 428], "127": [0, 3], "297": [0, 2], "522": [0, 736]}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
tags
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
*.o
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Filip Pancik <far.b3yond.driv3n@gmail.com>
|
||||||
@@ -0,0 +1,622 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
CFLAGS=-Wall -DMOD_$(mod) -g -Isrc/include -Isrc/include/proto -I../hm_base/src/include -I/usr/include/json-c/ -Iscript/mechanics/include #-DTURNOFF_TIMER -DMANA_ZERO -DTEST_DECK -DSPELL_ZERO_MANA
|
||||||
|
LIBS=-lev -lhmbase -lm -ljson-c -lcouchbase
|
||||||
|
LIBPATH=-L../hm_base/lib
|
||||||
|
TARGET=hm_gameserver
|
||||||
|
|
||||||
|
SOURCES=$(shell find src -type f -iname '*.c')
|
||||||
|
|
||||||
|
OBJECTS=$(foreach x, $(basename $(SOURCES)), $(x).o)
|
||||||
|
|
||||||
|
all: base script hm_gameserver
|
||||||
|
|
||||||
|
base:
|
||||||
|
$(MAKE) -C ../hm_base target=game
|
||||||
|
|
||||||
|
hm_gameserver:
|
||||||
|
$(CC) $(SOURCES) $(CFLAGS) $(LIBPATH) -o $(TARGET) $(LIBS)
|
||||||
|
|
||||||
|
script:
|
||||||
|
mkdir -p script/mechanics/include
|
||||||
|
cd script/ && python entities.py
|
||||||
|
cd script/mechanics/ && python main.py
|
||||||
|
cd script/ && python flags.py
|
||||||
|
cd script/ && python entities.py
|
||||||
|
cd script/mechanics/ && python main.py
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJECTS) $(TARGET) tags \
|
||||||
|
script/flags_sections \
|
||||||
|
script/mechanics/*.pyc \
|
||||||
|
src/flag_def.c \
|
||||||
|
src/proto/ent.c \
|
||||||
|
src/proto/ent_sections.c \
|
||||||
|
src/levelup.c \
|
||||||
|
src/include/levelup.h \
|
||||||
|
src/include/flag_def.h \
|
||||||
|
src/include/proto/ent_gen.h \
|
||||||
|
script/mechanics/include/*.h
|
||||||
|
|
||||||
|
.PHONY: all hm_gameserver script
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# hm_gameserver #
|
||||||
|
|
||||||
|
hm_gameserver is a HearthStone hearthmod gameserver. This server daemon is part of hearthmod stack which allows user to create custom modes and cards.
|
||||||
|
|
||||||
|
## Dependencies ##
|
||||||
|
|
||||||
|
- libev >= 4.22
|
||||||
|
- libjson-c >= 0.11
|
||||||
|
- libcouchbase >= 2.5.8
|
||||||
|
- libhmbase >= 0.1
|
||||||
|
|
||||||
|
## Compatiblity ##
|
||||||
|
|
||||||
|
hm_gameserver is compatible with HearthStone client 5.2.x.
|
||||||
|
|
||||||
|
## Compilation ##
|
||||||
|
|
||||||
|
cd hm_gameserver && make
|
||||||
|
|
||||||
|
# This is not a standalone project!
|
||||||
|
|
||||||
|
[hm_gameserver](https://github.com/farb3yonddriv3n/hm_gameserver) is part of [hearthmod software stack](https://github.com/hearthmod/hearthmod)
|
||||||
@@ -0,0 +1,731 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Game entity
|
||||||
|
name="Game Entity" card=GAME_ENTITY tags={10:85,20:1,49:1,198:4,202:1,204:2}
|
||||||
|
|
||||||
|
# Mana Card
|
||||||
|
name="Coin" card=GAME_005 tags={49:3,202:5,313:1}
|
||||||
|
|
||||||
|
# Player1
|
||||||
|
name="Player1" card=PLAYER1 tags={7:75,17:1,27:64,28:10,29:4,30:1,31:1,49:1,176:10,202:2,272:1,399:4}
|
||||||
|
|
||||||
|
# Player2
|
||||||
|
name="Player2" card=PLAYER2 tags={7:75,17:1,23:1,24:1,27:66,28:10,29:4,30:2,31:2,49:1,176:10,202:2,272:1,399:3}
|
||||||
|
|
||||||
|
# Power of the Horde
|
||||||
|
name="Kill Roshan" card=PRO_001c tags={183:11,202:5,48:30,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# The Sentinel
|
||||||
|
name="The Sentinel" card=TB_SPT_Boss tags={183:18,202:3,47:0,45:30,380:39537,} custom=1
|
||||||
|
|
||||||
|
# The Scourge
|
||||||
|
name="The Scourge " card=LOEA04_01 tags={183:20,45:30,330:0,331:0,380:16231,202:3,} custom=1
|
||||||
|
|
||||||
|
# Enrage
|
||||||
|
name="Tether" card=NAX12_04e tags={183:12,202:6,330:0,331:0,338:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Lantern of Power
|
||||||
|
name="Grow" card=LOEA16_3e tags={183:20,202:6,330:0,331:0,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Lothar's Left Greave
|
||||||
|
name="Arcane Boots" card=LOEA16_9 tags={183:20,202:5,48:0,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Mountain Giant
|
||||||
|
name="Tiny" card=EX1_105 tags={183:3,202:4,201:3,203:5,48:1,47:0,45:1,251:6,321:1,} custom=1 attachment=LOEA16_3e
|
||||||
|
|
||||||
|
# Youthful Brewmaster
|
||||||
|
name="Youthful Brewmaster" card=EX1_049 tags={183:3,202:4,201:2,203:1,48:2,47:3,45:2,251:6,321:1,330:0,331:0,218:1,} custom=1
|
||||||
|
|
||||||
|
# Brann Bronzebeard
|
||||||
|
name="Karroch, the Beastmaster" card=LOE_077 tags={183:20,202:4,203:5,114:1,321:1,48:5,47:2,45:3,330:0,331:0,362:0,} custom=1
|
||||||
|
|
||||||
|
# Abomination
|
||||||
|
name="Pudge, the Butcher" card=EX1_097 tags={183:3,202:4,201:3,203:3,48:5,47:0,45:4,251:6,321:1,330:0,331:0,190:0,217:0,} custom=1
|
||||||
|
|
||||||
|
# Piloted Sky Golem
|
||||||
|
name="Boush, the Tinker" card=GVG_105 tags={183:13,321:1,48:3,202:4,203:4,47:1,45:2,200:17,330:0,331:0,217:1,} custom=1
|
||||||
|
|
||||||
|
# Icehowl
|
||||||
|
[AT_125]
|
||||||
|
|
||||||
|
# Skeleton
|
||||||
|
name="Skeleton" card=NAX4_03H tags={183:12,202:4,48:7,47:6,45:5,} custom=1
|
||||||
|
|
||||||
|
# Skeleton Knight
|
||||||
|
name="The Skeleton King" card=AT_128 tags={183:15,321:1,203:5,202:4,48:7,47:6,45:5,114:1,330:0,331:0,217:1,} custom=1
|
||||||
|
|
||||||
|
# Deathwing
|
||||||
|
name="Deathwing" card=NEW1_030 tags={183:3,203:5,202:4,48:10,47:12,45:12,200:24,114:1,321:1,330:0,331:0,218:1,} custom=1
|
||||||
|
|
||||||
|
# Treant
|
||||||
|
name="Treant" card=EX1_158t tags={183:3,202:4,201:3,199:2,251:1,47:1,45:2,48:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Velen's Chosen
|
||||||
|
name="Guardian Greaves" card=GVG_010 tags={183:13,203:1,202:5,48:0,199:6,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Cabalist's Tome
|
||||||
|
name="Arcane Books" card=OG_090 tags={183:21,321:1,203:4,202:5,48:0,199:4,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Seal of Champions
|
||||||
|
name="Black King Bar" card=AT_074 tags={183:15,321:1,203:1,202:5,48:2,199:5,330:0,331:0,} custom=1 attachment=AT_074e2
|
||||||
|
|
||||||
|
# Seal of Champions E
|
||||||
|
name="Magic Immunity" card=AT_074e2 tags={183:15,202:6,199:5,330:0,331:0,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Dagon
|
||||||
|
name="Dagon" card=BRMA11_3 tags={183:14,202:5,48:1,47:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Sparring Partner
|
||||||
|
[AT_069]
|
||||||
|
|
||||||
|
# Divine Rapier E
|
||||||
|
name="Divine Rapier" card=FP1_020e tags={183:12,202:6,199:5,330:1,331:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Desolator
|
||||||
|
name="Desolator" card=LOEA06_03 tags={183:20,202:5,48:2,330:0,331:0,} custom=1 attachment=LOEA06_03e
|
||||||
|
|
||||||
|
# Desolator E
|
||||||
|
name="Desolate" card=LOEA06_03e tags={183:20,202:6,330:0,331:0,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Rooted
|
||||||
|
name="Level 2" card=EX1_178ae tags={183:3,202:6,199:2,330:1,331:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Inner Rage
|
||||||
|
name="Satanic" card=EX1_607 tags={183:3,203:5,202:5,48:3,201:3,199:10,321:1,} custom=1 attachment=EX1_607e
|
||||||
|
|
||||||
|
# Angry Chicken
|
||||||
|
name="Courier" card=EX1_009 tags={321:1,183:3,203:3,202:4,48:1,47:2,45:1,330:0,331:0,200:20,212:1,} custom=1
|
||||||
|
|
||||||
|
# Repel
|
||||||
|
[LOEA16_20]
|
||||||
|
|
||||||
|
# Cursed Blade
|
||||||
|
name="Echo Sabre " card=LOE_118 tags={183:20,321:1,203:3,202:7,48:2,47:0,187:3,199:10,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Shadowflame
|
||||||
|
name="Requiem of Souls" card=EX1_303 tags={183:3,202:5,201:3,199:9,203:3,48:4,251:1,268:2,321:1,330:0,331:0,370:1,} custom=1
|
||||||
|
|
||||||
|
# Demonfire E
|
||||||
|
name="Necromastery" card=EX1_596e tags={183:3,203:1,202:6,48:0,201:3,199:9,330:1,331:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Void Crusher
|
||||||
|
name="Eidolon" card=AT_023 tags={183:15,321:1,203:3,202:4,48:2,47:2,45:2,199:9,200:15,330:0,331:0,403:0,} custom=1
|
||||||
|
|
||||||
|
# Forbidden Shaping
|
||||||
|
name="Demonic Conversion" card=OG_101 tags={183:21,321:1,203:4,202:5,48:3,199:6,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Charge E
|
||||||
|
name="Level 1" card=CS2_103e2 tags={183:2,202:6,199:10,330:0,331:0,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Inner Rage E
|
||||||
|
name="Satanic" card=EX1_607e tags={183:3,202:6,199:10,330:1,331:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Inner Fire E
|
||||||
|
name="Level 3" card=CS1_129e tags={183:3,202:6,199:6,330:1,331:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Twisting Nether
|
||||||
|
name="The Black Hole" card=EX1_312 tags={183:3,202:5,201:3,199:9,203:4,48:8,251:1,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Mal Ganis
|
||||||
|
[GVG_021]
|
||||||
|
|
||||||
|
# Lay on Hands
|
||||||
|
name="Purification" card=EX1_354 tags={183:3,202:5,201:3,199:5,203:4,48:8,251:1,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Flame Lance
|
||||||
|
name="Laguna Blade" card=AT_001 tags={183:15,321:1,203:1,202:5,48:8,199:4,47:10,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Dragon's Breath
|
||||||
|
name="Dragon's Breath" card=BRM_003 tags={183:14,321:1,203:1,202:5,48:3,199:4,47:2,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Confessor Paletress
|
||||||
|
name="Lina" card=AT_018 tags={183:15,321:1,203:5,202:4,48:2,47:1,45:14,199:6,114:1,330:0,331:0,200:16,} custom=1 level2=BRM_003 level3=AT_001
|
||||||
|
|
||||||
|
# Lightning Storm
|
||||||
|
name="God's Wrath" card=EX1_259 tags={183:3,202:5,201:3,199:8,203:3,48:6,251:1,47:3,321:1,330:0,331:0,215:1,} custom=1
|
||||||
|
|
||||||
|
# Forked Lightning
|
||||||
|
name="Forked Lightning" card=EX1_251 tags={183:3,202:5,201:3,199:8,203:1,48:2,251:1,47:1,321:1,330:0,331:0,215:1,} custom=1
|
||||||
|
|
||||||
|
# Archmage Antonidas
|
||||||
|
name="Zeus" card=EX1_559 tags={183:3,203:5,202:4,48:3,47:1,45:15,201:3,251:3,199:4,114:1,321:1,330:0,331:0,32:1,} custom=1 level2=EX1_251 level3=EX1_259
|
||||||
|
|
||||||
|
# Commanding Shout
|
||||||
|
name="Warcry" card=NEW1_036 tags={183:3,203:3,202:5,48:1,199:10,321:1,330:0,331:0,} custom=1 attachment=NEW1_036e
|
||||||
|
|
||||||
|
# Commanding Shout
|
||||||
|
name="Sven: Warcry" card=NEW1_036e tags={183:3,202:6,199:10,330:0,331:0,338:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Druid of the Claw
|
||||||
|
name="Ursa" card=EX1_165t2 tags={183:3,203:5,202:4,48:4,47:3,45:21,199:2,330:0,331:0,200:20,190:0,} custom=1 level2=CS2_012 level3=CS2_011
|
||||||
|
|
||||||
|
# Open Wounds
|
||||||
|
name="Wounded" card=AT_039e tags={183:15,202:6,199:2,330:0,331:0,338:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Divine Strength
|
||||||
|
name="God's Strength" card=OG_223 tags={183:21,321:1,203:1,202:5,48:3,199:5,} custom=1 attachment=OG_223e
|
||||||
|
|
||||||
|
# Optimism
|
||||||
|
name="Sven: God's Strength" card=OG_223e tags={183:21,202:6,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Tirion Fordring
|
||||||
|
name="Sven" card=EX1_383 tags={183:3,203:5,202:4,48:3,47:3,45:16,201:3,199:5,251:1,114:1,321:1,330:0,331:0,194:0,190:0,217:0,} custom=1 level2=NEW1_036 level3=OG_223
|
||||||
|
|
||||||
|
# Windfury
|
||||||
|
[CS2_039]
|
||||||
|
|
||||||
|
# Corruption
|
||||||
|
name="Corruption" card=CS2_063 tags={183:2,202:5,201:3,199:9,203:1,48:1,251:1,321:1,330:0,331:0,} custom=1 attachment=CS2_063e
|
||||||
|
# Corruption E
|
||||||
|
name="Corruption" card=CS2_063e tags={183:2,202:6,199:9,330:2,331:2,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Hunter's Mark
|
||||||
|
[CS2_084] attachment=CS2_084e
|
||||||
|
# Hunter's Mark E
|
||||||
|
name="Hunter's Mark E" card=CS2_084e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Assasinate
|
||||||
|
name="Assassinate" card=CS2_076 tags={183:2,202:5,201:3,199:7,203:2,48:5,251:6,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Shadow Word: Death
|
||||||
|
[EX1_622]
|
||||||
|
|
||||||
|
# Shadow Word: Pain
|
||||||
|
name="Shadow Word: Pain" card=CS2_234 tags={321:1,183:2,203:2,202:5,48:2,199:6,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Execute
|
||||||
|
name="Culling Blade" card=CS2_108 tags={183:2,202:5,201:3,199:10,203:2,48:3,251:1,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Illidan
|
||||||
|
name="Terrorblade" card=EX1_614 tags={183:3,203:5,202:4,48:6,45:1,47:5,201:3,251:6,114:1,321:1,330:0,331:0,200:15,32:1,} custom=1
|
||||||
|
|
||||||
|
# Hand of Protection
|
||||||
|
name="Guardian Angel" card=EX1_371 tags={183:2,203:2,202:5,48:2,199:5,201:3,251:1,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Polymorph
|
||||||
|
[CS2_022] attachment=CS2_022e
|
||||||
|
name="Polymorph E" card=CS2_022e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Hex
|
||||||
|
[EX1_246] attachment=EX1_246e
|
||||||
|
# Hex E
|
||||||
|
name="Hex E" card="EX1_246e" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Blessing of Kings
|
||||||
|
[CS2_092] attachment=CS2_092e
|
||||||
|
# Blessing of Kings E
|
||||||
|
name="Blessing of Kings E" card="CS2_092e" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Blessing of Might
|
||||||
|
[CS2_087] attachment=CS2_087e
|
||||||
|
# Blessing of Might E
|
||||||
|
name="Blessing of Might E" card="CS2_087e" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Power Word: Shield
|
||||||
|
[CS2_004] attachment=CS2_004e
|
||||||
|
# Power Word: Shield E
|
||||||
|
name="Power Word: Shield E" card="CS2_004e" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Charge
|
||||||
|
[CS2_103] attachment=CS2_103e2
|
||||||
|
# Charge E
|
||||||
|
#name="Charge E" card="CS2_103e2" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Mark of the Wild
|
||||||
|
[CS2_009] attachment=CS2_009e
|
||||||
|
# Mark of the Wild E
|
||||||
|
name="Mark of the Wild E" card="CS2_009e" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Ancestral Healing
|
||||||
|
[CS2_041] attachment=CS2_041e
|
||||||
|
# Ancestral Infusion
|
||||||
|
name="Ancestral Infusion" card="CS2_041e" tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Rockbiter Weapon
|
||||||
|
[CS2_045] attachment=CS2_045e
|
||||||
|
# Rockbiter Weapon E
|
||||||
|
name="Rockbiter Weapon E" card=CS2_045e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Divine spirit
|
||||||
|
[CS2_236]
|
||||||
|
|
||||||
|
# Bloodlust
|
||||||
|
[CS2_046] attachment=CS2_046e
|
||||||
|
# Bloodlust E
|
||||||
|
name="Bloodlust E" card=CS2_046e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Claw
|
||||||
|
[CS2_005] attachment=CS2_005o
|
||||||
|
# Claw E
|
||||||
|
name="Claw E" card=CS2_005o tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Heroic Strike
|
||||||
|
[CS2_105] attachment=CS2_105e
|
||||||
|
# Heroic Strike E
|
||||||
|
name="Heroic Strike E" card=CS2_105e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Savage Roar
|
||||||
|
name="Enrage" card=CS2_011 tags={183:2,202:5,201:3,199:2,203:1,48:3,251:1,321:1,330:0,331:0,} custom=1 attachment=CS2_011o
|
||||||
|
# Savage Roar E
|
||||||
|
name="Enraged" card=CS2_011o tags={183:2,202:6,199:2,330:1,331:1,338:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Warrior
|
||||||
|
name="Warrior" card=HERO_01 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Shamman
|
||||||
|
name="Shamman" card=HERO_02 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Rogue
|
||||||
|
#name="Rogue" card=TB_SPT_Boss tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Paladin
|
||||||
|
name="Paladin" card=HERO_04 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Hunter
|
||||||
|
name="Hunter" card=HERO_05 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Druid
|
||||||
|
name="Druid" card=HERO_06 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Warlock
|
||||||
|
name="Warlock" card=HERO_07 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Mage
|
||||||
|
name="Mage" card=HERO_08 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Priest
|
||||||
|
#name="Priest" card=LOEA04_01 tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# King of Khaz Modan
|
||||||
|
name="King of Khaz Modan" card=HERO_01a tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Blood Knight Matriarch
|
||||||
|
name="Blood Knight Matriarch" card=HERO_04a tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Alleria Windranger
|
||||||
|
name="Alleria Windranger" card=HERO_05a tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Guardian Medivh
|
||||||
|
name="Guardian Medivh" card=HERO_08a tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
# Khadgar
|
||||||
|
name="Khadgar" card=HERO_08b tags={12:1,45:30,49:1,201:3,202:3,203:2} flags=(CARD_HERO)
|
||||||
|
|
||||||
|
# Ice lance
|
||||||
|
#CS2_031 tags={12:1,47:0,48:1,49:3,201:3,202:5,203:2,264:1} flags=(CARD_SPELL|CARD_SPELL_DAMAGE|CARD_TARGETING|CARD_FREEZE|CARD_TARGET_FROZEN_4_DMG)
|
||||||
|
|
||||||
|
# Holy Smite
|
||||||
|
[CS1_130]
|
||||||
|
|
||||||
|
# Fireball
|
||||||
|
[CS2_029]
|
||||||
|
|
||||||
|
# Swipe
|
||||||
|
name="Swipes" card=CS2_012 tags={183:2,202:5,201:3,199:2,203:1,48:2,251:1,47:2,321:1,330:0,331:0,} custom=1 attachment=AT_039e
|
||||||
|
|
||||||
|
# Hammer of Wrath
|
||||||
|
[CS2_094]
|
||||||
|
|
||||||
|
# Backstab
|
||||||
|
name="Backstab" card=CS2_072 tags={183:2,202:5,201:3,199:7,203:2,251:6,48:0,47:2,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Drain Life
|
||||||
|
[CS2_061]
|
||||||
|
|
||||||
|
# Sacrificial Pact
|
||||||
|
[NEW1_003]
|
||||||
|
|
||||||
|
# Arcane Shot
|
||||||
|
name="Arcane Shot" card=DS1_185 tags={183:2,202:5,201:3,199:3,203:2,48:1,251:8,47:2,321:1,} custom=1
|
||||||
|
|
||||||
|
# Soulfire
|
||||||
|
[EX1_308]
|
||||||
|
|
||||||
|
# Mortal Coil
|
||||||
|
[EX1_302]
|
||||||
|
|
||||||
|
# Shield Block
|
||||||
|
[EX1_606]
|
||||||
|
|
||||||
|
# Shiv
|
||||||
|
[EX1_278]
|
||||||
|
|
||||||
|
# Starfire
|
||||||
|
[EX1_173]
|
||||||
|
|
||||||
|
# Moonfire
|
||||||
|
[CS2_008]
|
||||||
|
|
||||||
|
# Kill Command
|
||||||
|
[EX1_539]
|
||||||
|
|
||||||
|
# Frostbolt
|
||||||
|
name="Frostbolt" card=CS2_024 tags={183:2,202:5,201:3,199:4,203:1,48:2,251:1,47:3,268:2,321:1,208:1,} custom=1
|
||||||
|
|
||||||
|
# Frost Shock
|
||||||
|
[CS2_037]
|
||||||
|
|
||||||
|
# Shadow Bolt
|
||||||
|
[CS2_057]
|
||||||
|
|
||||||
|
# Feral Rage - choose one
|
||||||
|
#OG_047 tags={12:1,48:2,49:3,201:3,202:5,203:2,264:1} flags=(CARD_SPELL|CARD_SPELL_DAMAGE|CARD_NONTARGET)
|
||||||
|
|
||||||
|
# Arcane intellect
|
||||||
|
name="Arcane Intellect" card=CS2_023 tags={183:2,202:5,201:3,199:4,203:2,48:3,251:1,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Sprint
|
||||||
|
name="Sprint" card=CS2_077 tags={183:2,202:5,201:3,199:7,203:1,48:7,251:1,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Arcane Explosion
|
||||||
|
[CS2_025]
|
||||||
|
|
||||||
|
# Arcane Missiles
|
||||||
|
[EX1_277]
|
||||||
|
|
||||||
|
# Tracking
|
||||||
|
[DS1_184]
|
||||||
|
|
||||||
|
# Sinister Strike
|
||||||
|
[CS2_075]
|
||||||
|
|
||||||
|
# Mind Blast
|
||||||
|
[DS1_233]
|
||||||
|
|
||||||
|
# Frost Nova
|
||||||
|
name="Shiva's Guard" card=CS2_026 tags={183:2,202:5,201:3,199:4,203:1,48:3,251:1,47:1,268:2,321:1,330:0,331:0,208:1,} custom=1
|
||||||
|
|
||||||
|
# Fan of Knives
|
||||||
|
[EX1_129]
|
||||||
|
|
||||||
|
# Cleave
|
||||||
|
[CS2_114]
|
||||||
|
|
||||||
|
# Multishot
|
||||||
|
[DS1_183]
|
||||||
|
|
||||||
|
# Mind Vision
|
||||||
|
[CS2_003]
|
||||||
|
|
||||||
|
# Flamestrike
|
||||||
|
[CS2_032]
|
||||||
|
|
||||||
|
# Whirlwind
|
||||||
|
name="Counter Helix" card=EX1_400 tags={183:2,202:5,201:3,199:10,203:1,48:0,251:1,47:1,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Consecration
|
||||||
|
[CS2_093]
|
||||||
|
|
||||||
|
# Holy Nova
|
||||||
|
name="Mekansm" card=CS1_112 tags={183:2,202:5,201:3,199:6,203:1,48:4,251:5,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Hellfire
|
||||||
|
[CS2_062]
|
||||||
|
|
||||||
|
# Water Elemental
|
||||||
|
[CS2_033]
|
||||||
|
|
||||||
|
################
|
||||||
|
# Aura
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Raid leader
|
||||||
|
[CS2_122] attachment=CS2_122e
|
||||||
|
# Enhanced
|
||||||
|
name="Enhanced" card=CS2_122e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Stormwind champion
|
||||||
|
name="Stormwind Champion" card=CS2_222 tags={183:2,202:4,201:2,203:1,48:7,47:6,45:6,251:1,321:1,330:0,331:0,362:1,} custom=1 attachment=CS2_222o
|
||||||
|
# Might of Stormwind
|
||||||
|
name="Might of Stormwind" card=CS2_222o tags={183:2,202:6,330:1,331:0,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Warsong Commander
|
||||||
|
[EX1_084] attachment=EX1_084e
|
||||||
|
# Charge
|
||||||
|
name="Charge" card=EX1_084e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Timber Wolf
|
||||||
|
[DS1_175] attachment=DS1_175o
|
||||||
|
# Furious Howl
|
||||||
|
name="Furious Howl" card=DS1_175o tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Gurubashi Berserker
|
||||||
|
[EX1_399] attachment=EX1_399e
|
||||||
|
# Berserking
|
||||||
|
name="Berserking" card=EX1_399e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
|
||||||
|
################
|
||||||
|
# Battlecry
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Dread Infernal
|
||||||
|
[CS2_064]
|
||||||
|
|
||||||
|
# Novice engineer
|
||||||
|
[EX1_015]
|
||||||
|
|
||||||
|
# Gnomish Inventor
|
||||||
|
[CS2_147]
|
||||||
|
|
||||||
|
# Darkscale Healer
|
||||||
|
[DS1_055]
|
||||||
|
|
||||||
|
# Guardian of Kings
|
||||||
|
name="Omniknight" card=CS2_088 tags={183:2,202:4,201:3,199:5,203:1,48:2,251:5,45:17,47:1,321:1,218:1,} custom=1
|
||||||
|
|
||||||
|
# Nightblade
|
||||||
|
name="Phantom Assassin" card=EX1_593 tags={183:2,203:2,202:4,48:4,45:2,47:4,201:3,321:1,218:1,} custom=1
|
||||||
|
|
||||||
|
# Acidic Swamp Ooze
|
||||||
|
[EX1_066]
|
||||||
|
|
||||||
|
# Voodoo doctor
|
||||||
|
name="Witch Doctor" card=EX1_011 tags={183:2,202:4,201:1,203:2,48:1,47:2,45:1,251:6,321:1,218:1,} custom=1
|
||||||
|
|
||||||
|
# Elven Archer
|
||||||
|
[CS2_189]
|
||||||
|
|
||||||
|
# Fire Elemental
|
||||||
|
name="Fire Elemental" card=CS2_042 tags={183:2,202:4,201:3,199:8,203:1,48:6,47:6,45:5,251:3,321:1,218:1,} custom=1
|
||||||
|
|
||||||
|
# Ironforge Rifleman
|
||||||
|
[CS2_141]
|
||||||
|
|
||||||
|
# Stormpike Commando
|
||||||
|
[CS2_150]
|
||||||
|
|
||||||
|
# Frostwolf Warlord
|
||||||
|
name="Legion Commander" card=CS2_226 tags={183:2,202:4,201:1,203:4,48:5,47:4,45:4,251:1,321:1,330:0,331:0,218:1,} custom=1 attachment=CS2_226e
|
||||||
|
# Frostwolf Banner
|
||||||
|
name="Frostwolf Banner" card=CS2_226e tags={183:2,202:6,330:1,331:1,} custom=1 flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Succubus
|
||||||
|
name="Queen of Pain" card=EX1_306 tags={183:2,202:4,201:3,199:9,200:15,203:2,48:3,47:4,45:3,251:1,268:2,321:1,218:1,} custom=1
|
||||||
|
|
||||||
|
# Sap
|
||||||
|
name="Sap" card=EX1_581 tags={183:2,203:2,202:5,48:2,201:3,199:7,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Mind Control
|
||||||
|
[CS1_113] attachment=CS1_113e
|
||||||
|
# Mind Control E
|
||||||
|
name="Mind Control E" card=CS1_113e tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
# Vanish
|
||||||
|
[NEW1_004]
|
||||||
|
|
||||||
|
################
|
||||||
|
# Spell damage
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Archmage
|
||||||
|
[CS2_155]
|
||||||
|
|
||||||
|
# Dalaran mage
|
||||||
|
[EX1_582]
|
||||||
|
|
||||||
|
# Kobold geomancer
|
||||||
|
[CS2_142]
|
||||||
|
|
||||||
|
# Ogre magi
|
||||||
|
[CS2_197]
|
||||||
|
|
||||||
|
################
|
||||||
|
# Charge
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Wolfirder
|
||||||
|
[CS2_124]
|
||||||
|
|
||||||
|
# Bluegill warrior
|
||||||
|
[CS2_173]
|
||||||
|
|
||||||
|
# Kor'kron elite
|
||||||
|
name="Mogul Khan, Axe" card=NEW1_011 tags={183:2,203:5,202:4,321:1,330:0,331:0,48:3,47:2,45:20,199:10,197:0,} custom=1 level3=CS2_108
|
||||||
|
|
||||||
|
# Stormwind knight
|
||||||
|
[CS2_131]
|
||||||
|
|
||||||
|
# Reckless rocketeer
|
||||||
|
[CS2_213]
|
||||||
|
|
||||||
|
# Stonetusk boar
|
||||||
|
name="Stonetusk Boar" card=CS2_171 tags={183:2,202:4,201:3,200:20,203:2,48:1,47:1,45:1,251:6,268:2,321:1,197:0,} custom=1
|
||||||
|
|
||||||
|
# Huffer
|
||||||
|
[NEW1_034] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
################
|
||||||
|
# Divine shield
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Scarlet Crusader
|
||||||
|
[EX1_020]
|
||||||
|
|
||||||
|
################
|
||||||
|
# Taunt
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Lord of the Arena
|
||||||
|
[CS2_162]
|
||||||
|
|
||||||
|
# Booty bay bodyguard
|
||||||
|
[CS2_187]
|
||||||
|
|
||||||
|
# Frostwolf Grunt
|
||||||
|
[CS2_121]
|
||||||
|
|
||||||
|
# Goldshire footman
|
||||||
|
[CS1_042]
|
||||||
|
|
||||||
|
# Ironbark protector
|
||||||
|
[CS2_232]
|
||||||
|
|
||||||
|
# Sen'jin Shieldmasta
|
||||||
|
[CS2_179]
|
||||||
|
|
||||||
|
# Voidwalker
|
||||||
|
name="Enigma" card=CS2_065 tags={183:2,202:4,201:3,199:9,200:15,203:5,48:2,45:15,251:9,47:1,268:2,321:1,190:0,} custom=1 level2=OG_101 level3=EX1_312
|
||||||
|
|
||||||
|
# Misha
|
||||||
|
[NEW1_032] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Frog
|
||||||
|
[hexfrog] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
################
|
||||||
|
# Totem
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Wrath of Air Totem
|
||||||
|
[CS2_052] flags=(CARD_UNCOLLECTIBLE|CARD_TOTEMIC_CALL_CHILD)
|
||||||
|
# Stoneclaw Totem
|
||||||
|
[CS2_051] flags=(CARD_UNCOLLECTIBLE|CARD_TOTEMIC_CALL_CHILD)
|
||||||
|
# Searing Totem
|
||||||
|
[CS2_050] flags=(CARD_UNCOLLECTIBLE|CARD_TOTEMIC_CALL_CHILD)
|
||||||
|
# Healing Totem
|
||||||
|
[NEW1_009] flags=(CARD_UNCOLLECTIBLE|CARD_TOTEMIC_CALL_CHILD)
|
||||||
|
# Flametongue Totem
|
||||||
|
[EX1_565] attachment=EX1_565o
|
||||||
|
# Flametongue
|
||||||
|
name="Flametongue" card=EX1_565o tags={12:1,49:6,202:6} flags=(CARD_ATTACHMENT)
|
||||||
|
|
||||||
|
################
|
||||||
|
# Summon
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Mirror Image
|
||||||
|
[CS2_027]
|
||||||
|
# Mirror Image
|
||||||
|
[CS2_mirror]
|
||||||
|
|
||||||
|
# Animal Companion
|
||||||
|
[NEW1_031]
|
||||||
|
|
||||||
|
# Dragonling Mechanic
|
||||||
|
[EX1_025]
|
||||||
|
# Mechanical Dragonling
|
||||||
|
[EX1_025t] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Murloc Tidehunter
|
||||||
|
[EX1_506]
|
||||||
|
# Murloc Scout
|
||||||
|
name="Murloc Scout" card=EX1_506a tags={183:2,202:4,201:3,200:14,203:1,47:1,45:1,251:1,48:0,} custom=1 flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Razorfen Hunter
|
||||||
|
[CS2_196]
|
||||||
|
|
||||||
|
# Leokk
|
||||||
|
[NEW1_033] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Starving Buzzard
|
||||||
|
name="Vulture" card=CS2_237 tags={321:1,183:2,203:1,202:4,48:1,47:1,45:1,199:3,200:20,330:0,331:0,32:1,} custom=1
|
||||||
|
|
||||||
|
# Sheep
|
||||||
|
[CS2_tk1] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Avator of the Coin
|
||||||
|
[GAME_002] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Boar
|
||||||
|
name="Boar" card=CS2_boar tags={183:2,202:4,201:3,203:1,47:1,45:1,251:1,48:1,200:20,330:0,331:0,} custom=1 flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
# Oasis Snapjaw
|
||||||
|
name="Oasis Snapjaw" card=CS2_119 tags={321:1,183:2,203:2,202:4,48:4,47:2,45:7,200:20,} custom=1
|
||||||
|
# Bloodfen Raptor
|
||||||
|
name="Bloodfen Raptor" card=CS2_172 tags={183:2,203:2,202:4,48:2,45:2,47:3,201:1,251:1,268:2,321:1,200:20,} custom=1
|
||||||
|
# Magma Rager
|
||||||
|
name="Shadow Fiend" card=CS2_118 tags={321:1,183:2,203:5,202:4,48:2,47:1,45:14,330:0,331:0,} custom=1 level3=EX1_303
|
||||||
|
|
||||||
|
# Puddlestomper
|
||||||
|
#GVG_064 tags={12:1,45:2,47:3,48:2,49:3,202:4,203:2} flags=(CARD_MINION)
|
||||||
|
# Wisp
|
||||||
|
name="Wisp" card=CS2_231 tags={183:3,203:1,202:4,48:2,45:2,47:0,201:3,251:7,} custom=1 attachment=NAX12_04e
|
||||||
|
|
||||||
|
# Core Hound
|
||||||
|
name="Core Hound" card=CS2_201 tags={321:1,183:2,203:1,202:4,48:7,47:9,45:5,200:20,} custom=1
|
||||||
|
|
||||||
|
# Murloc Raider
|
||||||
|
name="Murloc Raider" card=CS2_168 tags={183:2,202:4,201:2,203:2,48:1,47:2,45:1,251:1,321:1,200:14,} custom=1
|
||||||
|
|
||||||
|
# River Crocolisk
|
||||||
|
name="River Crocolisk" card=CS2_120 tags={321:1,183:2,203:2,202:4,48:2,47:2,45:3,200:20,} custom=1
|
||||||
|
|
||||||
|
# Boulderfist Ogre
|
||||||
|
name="Boulderfist Ogre" card=CS2_200 tags={321:1,183:2,203:2,202:4,48:6,47:6,45:7,} custom=1
|
||||||
|
|
||||||
|
# Chillwind Yeti
|
||||||
|
name="Chillwind Yeti" card=CS2_182 tags={183:2,202:4,201:3,203:1,48:4,47:4,45:5,251:6,268:2,321:1,330:0,331:0,} custom=1
|
||||||
|
|
||||||
|
# Fireblast
|
||||||
|
name="Fireblast" card=CS2_034 tags={12:1,47:1,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_TARGETING|CARD_SPELL|CARD_HP_SPELL_DAMAGE)
|
||||||
|
|
||||||
|
# Lesser Heal
|
||||||
|
# name="Lesser Heal" card=CS1h_001 tags={12:1,47:2,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_TARGETING|CARD_SPELL|CARD_SPELL_HEAL)
|
||||||
|
|
||||||
|
# Lesser Heal
|
||||||
|
name="Lesser Heal" card=CS1h_001 tags={183:2,202:10,201:3,199:6,203:2,48:2,251:1,} custom=1
|
||||||
|
|
||||||
|
# Healing Touch
|
||||||
|
[CS2_007]
|
||||||
|
|
||||||
|
# Holy Light
|
||||||
|
[CS2_089]
|
||||||
|
|
||||||
|
# Reinforce
|
||||||
|
name="Reinforce" card=CS2_101 tags={12:1,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_SPELL|CARD_NONTARGET|CARD_HP_REINFORCE|CARD_SUMMON)
|
||||||
|
# Silverhand Recruit
|
||||||
|
[CS2_101t] flags=(CARD_MINION|CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Dagger Mastery
|
||||||
|
name="Dagger Mastery" card=CS2_083b tags={12:1,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_SPELL|CARD_NONTARGET|CARD_HP_DAGGERMASTERY|CARD_SUMMON)
|
||||||
|
|
||||||
|
################
|
||||||
|
# Weapon
|
||||||
|
###############
|
||||||
|
|
||||||
|
# Wicked Knife
|
||||||
|
[CS2_082] flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# Assassin's Blade
|
||||||
|
[CS2_080]
|
||||||
|
|
||||||
|
# Truesilver Champion
|
||||||
|
name="Divine Rapier" card=CS2_097 tags={183:2,202:7,201:3,199:5,203:1,48:5,47:8,187:1,251:6,321:1,330:0,331:0,32:1,} custom=1
|
||||||
|
|
||||||
|
# Fiery War Axe
|
||||||
|
[CS2_106]
|
||||||
|
|
||||||
|
# Light's Justice
|
||||||
|
[CS2_091]
|
||||||
|
|
||||||
|
# Arcanite reaper
|
||||||
|
[CS2_112]
|
||||||
|
|
||||||
|
##############
|
||||||
|
|
||||||
|
# Totemic Call
|
||||||
|
[CS2_049] tags={12:1,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_SPELL|CARD_NONTARGET|CARD_SUMMON|CARD_HP_TOTEMIC_CALL)
|
||||||
|
|
||||||
|
# Shapeshift
|
||||||
|
[CS2_017] tags={12:1,47:1,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_SPELL|CARD_NONTARGET|CARD_HP_SHAPESHIFT|CARD_SUMMON)
|
||||||
|
|
||||||
|
# Armor Up
|
||||||
|
[CS2_102] tags={12:1,47:2,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_SPELL|CARD_NONTARGET|CARD_HP_ARMORUP|CARD_SUMMON)
|
||||||
|
|
||||||
|
# Life Tap
|
||||||
|
[CS2_056] tags={12:1,47:2,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_SPELL|CARD_NONTARGET|CARD_HP_LIFETAP|CARD_SUMMON)
|
||||||
|
|
||||||
|
# Steady Shot
|
||||||
|
[DS1h_292] tags={12:1,47:2,48:2,49:1,201:3,202:10,203:2} flags=(CARD_HEROPOWER|CARD_TARGETING|CARD_SPELL|CARD_HP_SPELL_DAMAGE|CARD_TARGET_HERO)
|
||||||
|
|
||||||
|
# Empty mana card
|
||||||
|
name="Empty card" card=MANA_CARD tags={12:1,49:3,263:5} flags=(CARD_UNCOLLECTIBLE)
|
||||||
|
|
||||||
|
# No card
|
||||||
|
name="No Card" card=NO_CARD tags={49:2} flags=(CARD_UNCOLLECTIBLE)
|
||||||
@@ -0,0 +1,274 @@
|
|||||||
|
'''
|
||||||
|
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/>.
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
allflags = []
|
||||||
|
index = 0
|
||||||
|
|
||||||
|
def parse(src):
|
||||||
|
global allflags
|
||||||
|
global index
|
||||||
|
entities = []
|
||||||
|
f = open(src, "r")
|
||||||
|
|
||||||
|
ri = 0
|
||||||
|
|
||||||
|
lines = f.readlines();
|
||||||
|
for l in lines:
|
||||||
|
ri = ri + 1
|
||||||
|
if(len(l) < 10): # new lines
|
||||||
|
continue
|
||||||
|
if(l[0] == "#"): # comment
|
||||||
|
continue
|
||||||
|
|
||||||
|
arr = shlex.split(l)
|
||||||
|
|
||||||
|
f = ''
|
||||||
|
att = ''
|
||||||
|
custom = ''
|
||||||
|
c = ''
|
||||||
|
t = ''
|
||||||
|
level2 = ''
|
||||||
|
level3 = ''
|
||||||
|
|
||||||
|
for a in arr:
|
||||||
|
sub = a.split("=")
|
||||||
|
if(len(sub) != 2):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if(sub[0] == "name"):
|
||||||
|
n = sub[1]
|
||||||
|
elif(sub[0] == "card"):
|
||||||
|
c = sub[1]
|
||||||
|
elif(sub[0] == "tags"):
|
||||||
|
t = sub[1]
|
||||||
|
elif(sub[0] == "flags"):
|
||||||
|
f = sub[1]
|
||||||
|
elif(sub[0] == "attachment"):
|
||||||
|
att = sub[1]
|
||||||
|
elif(sub[0] == "custom"):
|
||||||
|
custom = sub[1]
|
||||||
|
elif(sub[0] == "level2"):
|
||||||
|
level2 = sub[1]
|
||||||
|
elif(sub[0] == "level3"):
|
||||||
|
level3 = sub[1]
|
||||||
|
else:
|
||||||
|
print 'parsing %s failed' % sub[0]
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if(len(c) == 0 or len(t) == 0):
|
||||||
|
continue
|
||||||
|
|
||||||
|
d = {}
|
||||||
|
|
||||||
|
if(len(level2) > 0):
|
||||||
|
d['level2'] = level2
|
||||||
|
|
||||||
|
if(len(level3) > 0):
|
||||||
|
d['level3'] = level3
|
||||||
|
|
||||||
|
d['desc'] = n
|
||||||
|
d['name'] = c
|
||||||
|
|
||||||
|
if(len(f) > 0):
|
||||||
|
flags = f.replace("\n", "")
|
||||||
|
allflags.append([index, flags, d['name']])
|
||||||
|
d['rawflags'] = flags
|
||||||
|
|
||||||
|
d['flags'] = '{{0, 0, 0, 0, 0, 0, 0, 0}}'
|
||||||
|
|
||||||
|
if(len(att) > 0):
|
||||||
|
d['attachment'] = att
|
||||||
|
|
||||||
|
d['tags'] = {}
|
||||||
|
if(len(t) > 0):
|
||||||
|
properties = t.replace(",}", "}").split(",")
|
||||||
|
for p in properties:
|
||||||
|
a = p.split(":")
|
||||||
|
idx = a[0].replace("{", "")
|
||||||
|
tz = a[1].replace("\n", "").replace("}", "")
|
||||||
|
d['tags'][idx] = tz
|
||||||
|
|
||||||
|
if(len(custom) > 0):
|
||||||
|
d['custom'] = custom
|
||||||
|
print 'Active card: ' + d['desc'] + ' [' + d['name'] + ']'
|
||||||
|
|
||||||
|
entities.append(d)
|
||||||
|
|
||||||
|
index = index + 1
|
||||||
|
return entities
|
||||||
|
|
||||||
|
def gen_js_cards(e):
|
||||||
|
out = 'var cards = [\n'
|
||||||
|
for d in e :
|
||||||
|
for key in d:
|
||||||
|
if(key == 'rawflags'):
|
||||||
|
if((d[key].find("CARD_MINION") > -1 or d[key].find("CARD_SPELL") > -1) and\
|
||||||
|
d[key].find("CARD_UNCOLLECTIBLE") == -1 and d[key].find("CARD_HERO") == -1 and\
|
||||||
|
d[key].find("CARD_HEROPOWER") == -1
|
||||||
|
):
|
||||||
|
out += '["%s", "%s"], \n' % (d['name'], d['desc'])
|
||||||
|
|
||||||
|
out += '];'
|
||||||
|
|
||||||
|
f = open("cards.js", "w")
|
||||||
|
f.write(out)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def gen_js_hp(e):
|
||||||
|
out = 'var cards_hp = [\n'
|
||||||
|
for d in e :
|
||||||
|
for key in d:
|
||||||
|
if(key == 'rawflags'):
|
||||||
|
if(d[key].find("CARD_HEROPOWER") > -1):
|
||||||
|
out += '["%s", "%s"], \n' % (d['name'], d['desc'])
|
||||||
|
|
||||||
|
out += '];'
|
||||||
|
|
||||||
|
f = open("cards_hp.js", "w")
|
||||||
|
f.write(out)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def gen_js_hero(e):
|
||||||
|
out = 'var cards_hero = [\n'
|
||||||
|
for d in e :
|
||||||
|
for key in d:
|
||||||
|
if(key == 'rawflags'):
|
||||||
|
if(d[key] == "(CARD_HERO)"):
|
||||||
|
out += '["%s", "%s"], \n' % (d['name'], d['desc'])
|
||||||
|
|
||||||
|
out += '];'
|
||||||
|
|
||||||
|
f = open("cards_hero.js", "w")
|
||||||
|
f.write(out)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def gen(e):
|
||||||
|
out = '#include <ent_gen.h>\n'
|
||||||
|
out += '#include <ent.h>\n'
|
||||||
|
header = '#ifndef ENTGEN_H_\n#define ENTGEN_H_\n\n#define MAX_ENTITIES %d\n' % len(e)
|
||||||
|
out += 'struct ent_s entities[MAX_ENTITIES] = {'
|
||||||
|
index = 0
|
||||||
|
beasts = []
|
||||||
|
totems = []
|
||||||
|
totemic_call = []
|
||||||
|
hp = []
|
||||||
|
|
||||||
|
for d in e:
|
||||||
|
flags = ''
|
||||||
|
attch = '(void *)0, '
|
||||||
|
val = '{'
|
||||||
|
level2 = "(void *)0, "
|
||||||
|
level3 = "(void *)0, "
|
||||||
|
|
||||||
|
for key in d:
|
||||||
|
if(key == 'name'):
|
||||||
|
start = '{ "%s", %d, %d, ' % (d[key], len(d[key]), len(d['tags']))
|
||||||
|
elif(key == 'desc'):
|
||||||
|
desc = '"%s", ' % d[key]
|
||||||
|
elif(key == 'level2'):
|
||||||
|
level2 = '"%s", ' % d[key]
|
||||||
|
elif(key == 'level3'):
|
||||||
|
level3 = '"%s", ' % d[key]
|
||||||
|
elif(key == 'flags'):
|
||||||
|
flags = '%s, ' % d[key]
|
||||||
|
elif(key == 'attachment'):
|
||||||
|
attch = "\"%s\", " % d[key]
|
||||||
|
elif(key == 'rawflags'):
|
||||||
|
tt = 1
|
||||||
|
elif(key == 'custom'):
|
||||||
|
tt = 1
|
||||||
|
elif(key == 'tags'):
|
||||||
|
for k, v in d[key].items():
|
||||||
|
val += '{ %s, %s }, ' % (k, v)
|
||||||
|
|
||||||
|
val += ' }} // %d \n, ' % index
|
||||||
|
|
||||||
|
out += start + level2 + level3 + desc + flags + attch + val
|
||||||
|
index = index + 1
|
||||||
|
|
||||||
|
out += '};'
|
||||||
|
|
||||||
|
out += '\n\nvoid entities_init() {\n'
|
||||||
|
for i in allflags:
|
||||||
|
arr = i[1].split("|")
|
||||||
|
for a in arr:
|
||||||
|
cm = a.replace("(", "").replace(")", "")
|
||||||
|
if(cm == "CARD_RACE_BEAST"):
|
||||||
|
beasts.append(i[2])
|
||||||
|
if(cm == "CARD_RACE_TOTEM"):
|
||||||
|
totems.append(i[2])
|
||||||
|
if(cm == "CARD_TOTEMIC_CALL_CHILD"):
|
||||||
|
totemic_call.append(i[2])
|
||||||
|
if(cm == "CARD_HEROPOWER"):
|
||||||
|
hp.append(i[2])
|
||||||
|
|
||||||
|
out += '\tflag(&entities[%s].flags, %s, FLAG_SET);\n' % (i[0], cm)
|
||||||
|
|
||||||
|
out += '}\n'
|
||||||
|
header += "#define MAX_BEASTS %d\n" % len(beasts)
|
||||||
|
header += "#define MAX_TOTEMS %d\n" % len(totems)
|
||||||
|
header += "#define MAX_TOTEMIC_CALL %d\n" % len(totemic_call)
|
||||||
|
header += "#define MAX_HEROPOWER %d\n" % len(hp)
|
||||||
|
|
||||||
|
out += "const char *race_beast[MAX_BEASTS] = {\n"
|
||||||
|
for b in beasts:
|
||||||
|
out += "\t\"%s\",\n" % b
|
||||||
|
out += "};\n"
|
||||||
|
|
||||||
|
out += "const char *race_totems[MAX_TOTEMS] = {\n"
|
||||||
|
for b in totems:
|
||||||
|
out += "\t\"%s\",\n" % b
|
||||||
|
out += "};\n"
|
||||||
|
|
||||||
|
out += "const char *totemic_call[MAX_TOTEMIC_CALL] = {\n"
|
||||||
|
for b in totemic_call:
|
||||||
|
out += "\t\"%s\",\n" % b
|
||||||
|
out += "};\n"
|
||||||
|
|
||||||
|
out += "const char *hp_list[MAX_HEROPOWER] = {\n"
|
||||||
|
for b in hp:
|
||||||
|
out += "\t\"%s\",\n" % b
|
||||||
|
out += "};\n"
|
||||||
|
|
||||||
|
f = open("../src/proto/ent.c", "w")
|
||||||
|
f.write(out)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
header += "const char *totemic_call[MAX_TOTEMIC_CALL];\n"
|
||||||
|
header += "const char *race_beast[MAX_BEASTS];\n"
|
||||||
|
header += "const char *race_totems[MAX_TOTEMS];\n"
|
||||||
|
header += "\n#endif"
|
||||||
|
f = open("../src/include/proto/ent_gen.h", "w")
|
||||||
|
f.write(header)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
basic = parse("custom_mod")
|
||||||
|
#classic = parse("cards/classic")
|
||||||
|
|
||||||
|
#e = basic + classic
|
||||||
|
e = basic
|
||||||
|
|
||||||
|
gen(e)
|
||||||
|
#gen_js_cards(e)
|
||||||
|
#gen_js_hp(e)
|
||||||
|
#gen_js_hero(e)
|
||||||
|
print 'total entities: %d' % len(e)
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
MECHANICS_DAMAGE , 1000
|
||||||
|
MECHANICS_HEALTH , 1000
|
||||||
|
MECHANICS_ATTACK , 1000
|
||||||
|
MECHANICS_ATTACK_DAMAGE, 1000
|
||||||
|
MECHANICS_ATTACK_HEAL, 1000
|
||||||
|
MECHANICS_HEROPOWER, 1000
|
||||||
|
MECHANICS_BATTLECRY_TRIGGER , 1000
|
||||||
|
MECHANICS_CHANGESIDES, 1000
|
||||||
|
MECHANICS_ARMOR, 1000
|
||||||
|
MECHANICS_DURABILITY, 1000
|
||||||
|
MECHANICS_DETACH, 1000
|
||||||
|
MECHANICS_SELECTED, 1000
|
||||||
|
MECHANICS_DESTROY_WEAPON, 1000
|
||||||
|
MECHANICS_TURN_TRIGGER, 1000
|
||||||
|
MECHANICS_COST, 1000
|
||||||
|
CARD_HAND , 1000
|
||||||
|
CARD_DESTROYED , 1001
|
||||||
|
CARD_BOARD , 1000
|
||||||
|
CARD_EXHAUSTED , 1000
|
||||||
|
CARD_HERO , 1000
|
||||||
|
CARD_HEROPOWER , 1000
|
||||||
|
CARD_HEROWEAPON, 1000
|
||||||
|
CARD_BOSS, 1000
|
||||||
|
CARD_TARGETING , 1000
|
||||||
|
CARD_NONTARGET , 1000
|
||||||
|
CARD_NONTARGET_BC , 1000
|
||||||
|
CARD_SPELL , 1000
|
||||||
|
CARD_SPELL_HEAL , 1000
|
||||||
|
CARD_SPELL_DAMAGE , 1000
|
||||||
|
CARD_HP_REINFORCE , 1000
|
||||||
|
CARD_HP_DAGGERMASTERY , 1000
|
||||||
|
CARD_HP_ARMORUP , 1000
|
||||||
|
CARD_HP_LIFETAP , 1000
|
||||||
|
CARD_HP_SHAPESHIFT , 1000
|
||||||
|
CARD_WINDFURY , 1000
|
||||||
|
CARD_DECK , 1000
|
||||||
|
CARD_TARGET_HERO , 1000
|
||||||
|
CARD_TARGET_MINIONS , 1000
|
||||||
|
CARD_TARGET_ENEMY_HERO , 1000
|
||||||
|
CARD_TARGET_ENEMY_MINIONS , 1000
|
||||||
|
CARD_TARGET_ALLY_HERO , 1000
|
||||||
|
CARD_TARGET_ALLY_MINIONS , 1000
|
||||||
|
CARD_TARGET_ALLY, 1000
|
||||||
|
CARD_TARGET_ENEMY, 1000
|
||||||
|
CARD_TARGET_ALL, 1000
|
||||||
|
CARD_HP_SPELL_DAMAGE , 1000
|
||||||
|
CARD_INNERFIRE , 1000
|
||||||
|
CARD_AOE_ENEMY_MINIONS , 1000
|
||||||
|
CARD_AOE_ALLENEMY , 1000
|
||||||
|
CARD_CHARGE , 1000
|
||||||
|
CARD_DIVINE_SHIELD , 1000
|
||||||
|
CARD_FREEZE , 1000
|
||||||
|
CARD_FROZEN , 1000
|
||||||
|
CARD_TARGET_FROZEN_4_DMG , 1000
|
||||||
|
CARD_BATTLECRY , 1000
|
||||||
|
CARD_BATTLECRY_DAMAGE3_ENEMY_HERO , 1000
|
||||||
|
CARD_BATTLECRY_TARGET , 1000
|
||||||
|
CARD_BATTLECRY_HEAL2_TARGET , 1000
|
||||||
|
CARD_BATTLECRY_DRAW1_CARD, 1000
|
||||||
|
CARD_DRAW2_CARD, 1000
|
||||||
|
CARD_DRAW4_CARD, 1000
|
||||||
|
CARD_DRAW_CARD, 1000
|
||||||
|
CARD_MINION, 1000
|
||||||
|
CARD_BUFF , 1000
|
||||||
|
CARD_DIVINESPIRIT, 1000
|
||||||
|
CARD_AOE, 1000
|
||||||
|
CARD_AOE_TARGET_ALL, 1000
|
||||||
|
CARD_HEAL_ALLIES, 1000
|
||||||
|
CARD_BATTLECRY_DAMAGE1_ALL, 1000
|
||||||
|
CARD_AOE_MINIONS, 1000
|
||||||
|
CARD_SUMMON, 1000
|
||||||
|
CARD_WEAPON_ROCKBITER, 1000
|
||||||
|
CARD_WEAPON, 1000
|
||||||
|
CARD_BOARD_WEAPON, 1000
|
||||||
|
CARD_SUMMON_CS2_MIRROR, 1000
|
||||||
|
CARD_BLESSING_OF_KINGS, 1000
|
||||||
|
CARD_BLOODLUST, 1000
|
||||||
|
CARD_BUFF_AOE, 1000
|
||||||
|
CARD_CORRUPTION, 1000
|
||||||
|
CARD_CORRUPTED, 1000
|
||||||
|
CARD_ATTACHMENT, 1000
|
||||||
|
CARD_RAID_LEADER, 1000
|
||||||
|
CARD_AURA, 1000
|
||||||
|
CARD_STORMWIND_CHAMPION, 1000
|
||||||
|
CARD_RACE_BEAST, 1000
|
||||||
|
CARD_RACE_MURLOC, 1000
|
||||||
|
CARD_TAUNT, 1000
|
||||||
|
CARD_SPELLPOWER, 1000
|
||||||
|
CARD_SAP, 1000
|
||||||
|
CARD_VANISH, 1000
|
||||||
|
CARD_SUMMON_ANIMAL_COMPANION, 1000
|
||||||
|
CARD_UNCOLLECTIBLE, 1000
|
||||||
|
CARD_BATTLECRY_SUMMON_DRAGONLING_MECHANIC, 1000
|
||||||
|
CARD_RACE_MECH, 1000
|
||||||
|
CARD_LEOKK, 1000
|
||||||
|
CARD_BATTLECRY_SUMMON_MURLOC_SCOUT, 1000
|
||||||
|
CARD_BATTLECRY_SUMMON_BOAR, 1000
|
||||||
|
CARD_BATTLECRY_SUMMON, 1000
|
||||||
|
CARD_RACE_TOTEM, 1000
|
||||||
|
CARD_RACE_DEMON, 1000
|
||||||
|
CARD_TURN_HEAL1_MINIONS, 1000
|
||||||
|
CARD_TOTEMIC_CALL_CHILD, 1000
|
||||||
|
CARD_HP_TOTEMIC_CALL, 1000
|
||||||
|
CARD_BATTLECRY_HEAL2_ALIES, 1000
|
||||||
|
CARD_BATTLECRY_HEAL6_ALLY_HERO, 1000
|
||||||
|
CARD_BATTLECRY_DAMAGE1_TARGET, 1000
|
||||||
|
CARD_BATTLECRY_DAMAGE2_TARGET, 1000
|
||||||
|
CARD_BATTLECRY_DAMAGE3_TARGET, 1000
|
||||||
|
CARD_BATTLECRY_FROSTWOLF_WARLORD, 1000
|
||||||
|
CARD_BATTLECRY_DISCARD1_CARD, 1000
|
||||||
|
CARD_DISCARD, 1000
|
||||||
|
CARD_MIND_CONTROL, 1000
|
||||||
|
CARD_AOE_CLEAVE, 1000
|
||||||
|
CARD_FAN_OF_KNIVES, 1000
|
||||||
|
CARD_KILL_COMMAND, 1000
|
||||||
|
CARD_MIND_VISION, 1000
|
||||||
|
CARD_DAMAGE_DRAW_CARD, 1000
|
||||||
|
CARD_SOULFIRE, 1000
|
||||||
|
CARD_MORTAL_COIL, 1000
|
||||||
|
CARD_DRAW1_CARD, 1000
|
||||||
|
CARD_ARMOR5, 1000
|
||||||
|
CARD_TRUESILVER_CHAMPION, 1000
|
||||||
|
CARD_STARVING_BUZZARD, 1000
|
||||||
|
CARD_SAVAGE_ROAR, 1000
|
||||||
|
CARD_WARSONG_COMMANDER, 1000
|
||||||
|
CARD_TIMBER_WOLF, 1000
|
||||||
|
CARD_FLAMETONGUE_TOTEM, 1000
|
||||||
|
CARD_GURU_BERSERKER, 1000
|
||||||
|
CARD_CLAW, 1000
|
||||||
|
CARD_MARK_OF_THE_WILD, 1000
|
||||||
|
CARD_HUNTERS_MARK, 1000
|
||||||
|
CARD_AOE_MULTISHOT, 1000
|
||||||
|
CARD_ANCESTRAL_HEALING, 1000
|
||||||
|
CARD_ROCKBITER_WEAPON, 1000
|
||||||
|
CARD_DRAIN_LIFE, 1000
|
||||||
|
CARD_SINISTER_STRIKE, 1000
|
||||||
|
CARD_ASSASINATE, 1000
|
||||||
|
CARD_MIND_BLAST, 1000
|
||||||
|
CARD_HAND_OF_PROTECTION, 1000
|
||||||
|
CARD_CHARGE_BUFF, 1000
|
||||||
|
CARD_HEROIC_STRIKE, 1000
|
||||||
|
CARD_EXECUTE, 1000
|
||||||
|
CARD_SHADOW_WORD_DEATH, 1000
|
||||||
|
CARD_SHADOW_WORD_PAIN, 1000
|
||||||
|
CARD_SACRIFITIAL_PACT, 1000
|
||||||
|
CARD_BATTLECRY_DESTROY_ENEMY_WEAPON, 1000
|
||||||
|
CARD_POWER_WORD_SHIELD, 1000
|
||||||
|
CARD_SWIPE, 1000
|
||||||
|
CARD_ARCANE_MISSILES, 1000
|
||||||
|
CARD_TRACKING, 1000
|
||||||
|
CARD_TRANSFORM, 1000
|
||||||
|
CARD_POLYMORPH, 1000
|
||||||
|
CARD_HIDE, 1000
|
||||||
|
CARD_LINKED, 1000
|
||||||
|
CARD_HEX, 1000
|
||||||
|
CARD_TARGET_UNDAMAGED_MINION, 1000
|
||||||
|
CARD_TARGET_DAMAGED_MINION, 1000
|
||||||
|
CARD_TARGET_3ATTACK_LESS, 1000
|
||||||
|
CARD_TARGET_5ATTACK_MORE, 1000
|
||||||
|
CARD_TARGET_30PERCENT_LESS, 1000
|
||||||
|
CARD_TARGET_DEMON, 1000
|
||||||
|
CARD_BLESSING_OF_MIGHT, 1000
|
||||||
|
CARD_TARGET_UNDAMAGED, 1000
|
||||||
|
CARD_ARCHMAGE_ANTONIDAS, 1000
|
||||||
|
CARD_TARGET_BC_AUTO, 1000
|
||||||
|
CARD_TARGET_BC_MANUAL, 1000
|
||||||
|
CARD_TARGET_BC_ALL, 1000
|
||||||
|
CARD_TARGETING_BC, 1000
|
||||||
|
CARD_TARGET_BC_ALLY, 1000
|
||||||
|
CARD_TARGET_BC_ENEMY, 1000
|
||||||
|
CARD_TARGET_BC_ENEMY_MINIONS, 1000
|
||||||
|
CARD_TARGET_BC_HERO, 1000
|
||||||
|
CARD_TARGET_BC_ENEMY_HERO, 1000
|
||||||
|
CARD_TARGET_BC_MINIONS, 1000
|
||||||
|
CARD_TARGET_BC_ALLY_MINIONS, 1000
|
||||||
|
CARD_TARGET_BC_ALLY_HERO, 1000
|
||||||
|
CARD_STEALTH, 1000
|
||||||
|
CARD_ATTACK, 1000
|
||||||
|
CARD_TARGET_URSA, 1000
|
||||||
|
CARD_TARGET_SVEN, 1000
|
||||||
|
CARD_LEVELUP, 1000
|
||||||
|
CARD_PIERCE_MAGIC_IMMUNITY, 1000
|
||||||
|
CARD_TARGET_ALLY_BOARD, 1000
|
||||||
|
CARD_TARGET_BOARD, 1000
|
||||||
|
CARD_TARGET_ENEMY_BOARD, 1000
|
||||||
|
CARD_TARGET_ALLY_BOSSES, 1000
|
||||||
|
CARD_TARGET_ENEMY_BOSSES, 1000
|
||||||
|
CARD_TARGET_BOSSES, 1000
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
'''
|
||||||
|
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/>.
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
|
||||||
|
def fwrite(f, content):
|
||||||
|
f = open(f, "w")
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def parse():
|
||||||
|
f = open("./flags", "r")
|
||||||
|
lines = f.readlines();
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
f = open("./flags_sections", "r")
|
||||||
|
lines = lines + f.readlines()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
ae = []
|
||||||
|
for l in lines:
|
||||||
|
|
||||||
|
elements = []
|
||||||
|
for ele in l.split(","):
|
||||||
|
elements.append(ele.replace(" ", "").replace("\n", ""))
|
||||||
|
|
||||||
|
ae.append(elements)
|
||||||
|
|
||||||
|
header = '#ifndef FLAG_DEF_H_\n#define FLAG_DEF_H_\n\n'
|
||||||
|
|
||||||
|
header += '#define MAX_FLAGS_DEF %d\n\n' % len(ae)
|
||||||
|
header += 'int flag_defs[MAX_FLAGS_DEF];\n'
|
||||||
|
header += 'enum flags_e {\n'
|
||||||
|
i = 0
|
||||||
|
for a in ae:
|
||||||
|
header += '\t%s = %s,\n' % (a[0], i)
|
||||||
|
i = i + 1
|
||||||
|
header += '};\n'
|
||||||
|
header += '#endif'
|
||||||
|
|
||||||
|
body = '#include <flag_def.h>\n\n'
|
||||||
|
body += 'int flag_defs[MAX_FLAGS_DEF] = {\n'
|
||||||
|
i = 0
|
||||||
|
for a in ae:
|
||||||
|
body += '%d, // index %d\n' % (int(a[1]), i)
|
||||||
|
i = i + 1
|
||||||
|
body += '};\n'
|
||||||
|
|
||||||
|
fwrite("../src/include/flag_def.h", header)
|
||||||
|
fwrite("../src/flag_def.c", body)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
e = parse()
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
@section
|
||||||
|
buff:code,target
|
||||||
|
battlecry:code,target
|
||||||
|
defender:code
|
||||||
|
properties:all,levelup
|
||||||
|
spell_aoe:code,target
|
||||||
|
spell:code,target
|
||||||
|
attack:code,target
|
||||||
|
attack_effect:code
|
||||||
|
weapon:code
|
||||||
|
endturn:code
|
||||||
|
onboard:code
|
||||||
|
destroyed:code
|
||||||
|
weapon_destroyed:code
|
||||||
|
idle:code
|
||||||
|
weapon_attack:code
|
||||||
|
attachment_attack:code
|
||||||
|
attack_effect_attachment:code
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Goldshire Footman
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$minions"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section properties" : {
|
||||||
|
"all": [ "taunt" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Holy Nova
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, allcards)
|
||||||
|
allcards = hsl_board_all_cards($attacker, $heroes_included);
|
||||||
|
|
||||||
|
def(card_list_s, cl)
|
||||||
|
foreach(cl, allcards) {
|
||||||
|
if(cl->card->controller == $attacker->controller) {
|
||||||
|
cl->card->receive.heal = 2;
|
||||||
|
} else {
|
||||||
|
cl->card->receive.damage = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack_aoe($attacker, allcards)
|
||||||
|
|
||||||
|
hsl_link_target($attacker, allcards)
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Holy Smite
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.damage = 2;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Mind Vision
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
def(card_s, card)
|
||||||
|
card = hsl_cards_get_hand_random($deck_opponent);
|
||||||
|
if(card) {
|
||||||
|
hsl_add_new_card_hand($deck_player, card->entity->name, holder)
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"target" : "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Power Word: Shield
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_change_health($defender, 2)
|
||||||
|
hsl_add_signle_attachment($player, $deck_player, $attacker, $defender);
|
||||||
|
|
||||||
|
hsl_draw_cards($player, $deck_player, draw_card, 1)
|
||||||
|
|
||||||
|
/* hsl_link_target($attacker, $defenders) */
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Claw
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
int change = 2;
|
||||||
|
hsl_buff_attack_expire(1, $ally_hero, change);
|
||||||
|
hsl_change_armor($ally_hero, change)
|
||||||
|
hsl_add_attachment($player, $attacker, $ally_hero, 1);
|
||||||
|
hsl_add_target($ally_hero, holder)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Healing Touch
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.heal = 8;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
hsl_link_target($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Moonfire
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
/* defender is linked by default */
|
||||||
|
$defender->receive.damage = 1;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Mark of the Wild
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_change_attack($defender, 2)
|
||||||
|
hsl_set_taunt($defender)
|
||||||
|
hsl_add_signle_attachment($player, $deck_player, $attacker, $defender);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Savage Roar
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
def(card_list_s, all)
|
||||||
|
all = hsl_board_friendly_cards($attacker, $heroes_included);
|
||||||
|
|
||||||
|
def(card_list_s, itm)
|
||||||
|
foreach(itm, all) {
|
||||||
|
hsl_buff_attack_expire(1, itm->card, 2);
|
||||||
|
hsl_add_attachment($player, $attacker, itm->card, 1);
|
||||||
|
hsl_add_defender(itm->card, holder)
|
||||||
|
}
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Swipe
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code": "
|
||||||
|
def(card_list_s, all)
|
||||||
|
all = hsl_board_enemy_cards($defender, $heroes_included);
|
||||||
|
$defender->receive.damage = 4;
|
||||||
|
|
||||||
|
def(card_list_s, itm)
|
||||||
|
foreach(itm, all) {
|
||||||
|
itm->card->receive.damage = 1;
|
||||||
|
hsl_add_target(itm->card, holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack($attacker, $defenders)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$enemy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Polymorph
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_transform($attacker, $defender, \"CS2_tk1\");
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$enemy_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Arcane Intellect
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_draw_cards($player, $deck_player, draw_card, 2)
|
||||||
|
",
|
||||||
|
"target" : "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Frostbolt
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.damage = 3;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section attack_effect" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_freeze($attacker, $defender)
|
||||||
|
"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section properties" : {
|
||||||
|
"all": [ "freeze" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Arcane Explosion
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, e)
|
||||||
|
e = hsl_board_enemy_cards($attacker, $heroes_excluded);
|
||||||
|
|
||||||
|
def(card_list_s, cl)
|
||||||
|
foreach(cl, e) {
|
||||||
|
cl->card->receive.damage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack_aoe($attacker, e)
|
||||||
|
hsl_link_target($attacker, e)
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Frost Nova
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, e)
|
||||||
|
e = hsl_board_enemy_cards($attacker, $heroes_excluded);
|
||||||
|
|
||||||
|
hsl_attack_aoe($attacker, e)
|
||||||
|
hsl_link_target($attacker, e)
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Mirror Image
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code": "
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 2; i++) {
|
||||||
|
hsl_summon_card($deck_player, \"CS2_mirror\", cardholder)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this just does the routine (destroying it etc..) with a played card */
|
||||||
|
hsl_attack_aoe($attacker, $defenders)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Fireball
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.damage = 6;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Flamestrike
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, e)
|
||||||
|
e = hsl_board_enemy_cards($attacker, $heroes_excluded);
|
||||||
|
|
||||||
|
def(card_list_s, cl)
|
||||||
|
foreach(cl, e) {
|
||||||
|
cl->card->receive.damage = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack_aoe($attacker, e)
|
||||||
|
hsl_link_target($attacker, e)
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Water Elemental
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$minions"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section attack_effect" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_freeze($attacker, $defender)
|
||||||
|
"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section properties" : {
|
||||||
|
"all": [ "freeze" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Frost Shock
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.damage = 1;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section attack_effect" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_freeze($attacker, $defender)
|
||||||
|
"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section properties" : {
|
||||||
|
"all": [ "freeze" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Windfury
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
setflag($defender, CARD_WINDFURY)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Ancestral Healing
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_set_fullhealth($defender)
|
||||||
|
hsl_set_taunt($defender)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Fire Elemental
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_s, def)
|
||||||
|
def = hsl_card($target);
|
||||||
|
if(def) {
|
||||||
|
hsl_attack_bc($attacker, def, 3)
|
||||||
|
}
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Rockbiter Weapon
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_buff_attack_expire(1, $defender, 3);
|
||||||
|
hsl_add_attachment($player, $attacker, $defender, 1);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Bloodlust
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
def(card_list_s, all)
|
||||||
|
all = hsl_board_friendly_cards($attacker, $heroes_excluded)
|
||||||
|
|
||||||
|
def(card_list_s, itm)
|
||||||
|
foreach(itm, all) {
|
||||||
|
hsl_buff_attack_expire(1, itm->card, 3);
|
||||||
|
hsl_add_attachment($player, $attacker, itm->card, 1);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Shadow Bolt
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.damage = 4;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Drain Life
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code": "
|
||||||
|
hsl_receive_damage($defender, 2);
|
||||||
|
|
||||||
|
hsl_receive_heal($ally_hero, 2);
|
||||||
|
hsl_add_target($ally_hero, holder);
|
||||||
|
|
||||||
|
hsl_attack($attacker, $defenders)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$enemy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Hellfire
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, allcards)
|
||||||
|
allcards = hsl_board_all_cards($attacker, $heroes_included);
|
||||||
|
|
||||||
|
def(card_list_s, cl)
|
||||||
|
foreach(cl, allcards) {
|
||||||
|
cl->card->receive.damage = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack_aoe($attacker, allcards)
|
||||||
|
|
||||||
|
hsl_link_target($attacker, allcards)
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Corruption
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_buff_corrupt_expire(2, $defender);
|
||||||
|
hsl_add_attachment($player, $attacker, $defender, 2);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Dread Infernal
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, allcards)
|
||||||
|
allcards = hsl_board_all_cards($attacker, $heroes_included);
|
||||||
|
|
||||||
|
def(card_list_s, cl)
|
||||||
|
foreach(cl, allcards) {
|
||||||
|
cl->card->receive.damage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack_aoe(attacker, allcards)
|
||||||
|
|
||||||
|
hsl_link_target(attacker, allcards)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Voidwalker
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$minions"
|
||||||
|
},
|
||||||
|
|
||||||
|
".section properties" : {
|
||||||
|
"all": [ "taunt" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Backstab
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_receive_damage($defender, 2);
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$undamaged_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Sinister Strike
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack_bc($attacker, $enemy_hero, 3)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Assassinate
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_destroy($defender);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$enemy_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Sprint
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_draw_cards($player, $deck_player, draw_card, 4)
|
||||||
|
",
|
||||||
|
"target" : "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Assassin's Blade
|
||||||
|
{
|
||||||
|
".section weapon" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_give_weapon($deck_player);
|
||||||
|
"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Wicked Knife
|
||||||
|
{
|
||||||
|
".section weapon" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_give_weapon($deck_player);
|
||||||
|
"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Blessing of Might
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_change_attack($defender, 3)
|
||||||
|
hsl_add_signle_attachment($player, $deck_player, $attacker, $defender);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Guardian of Kings
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_heal($attacker, $ally_hero, 6)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Holy Light
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.heal = 6;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
hsl_link_target($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Light's Justice
|
||||||
|
{
|
||||||
|
".section weapon" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_give_weapon($deck_player);
|
||||||
|
"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Blessing of Kings
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_change_attack($defender, 4)
|
||||||
|
hsl_change_health($defender, 4)
|
||||||
|
hsl_add_signle_attachment($player, $deck_player, $attacker, $defender);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Consecration
|
||||||
|
{
|
||||||
|
".section spell_aoe" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_list_s, e)
|
||||||
|
e = hsl_board_enemy_cards($attacker, $heroes_included);
|
||||||
|
|
||||||
|
def(card_list_s, cl)
|
||||||
|
foreach(cl, e) {
|
||||||
|
cl->card->receive.damage = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
hsl_attack_aoe($attacker, e)
|
||||||
|
hsl_link_target($attacker, e)
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Hammer of Wrath
|
||||||
|
{
|
||||||
|
".section spell" : {
|
||||||
|
"code" : "
|
||||||
|
$defender->receive.damage = 3;
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
|
||||||
|
hsl_draw_cards($player, $deck_player, draw_card, 1)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Heroic Strike
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code": "
|
||||||
|
hsl_buff_attack_expire(1, $ally_hero, 4);
|
||||||
|
hsl_add_attachment($player, $attacker, $ally_hero, 1);
|
||||||
|
|
||||||
|
",
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Fiery War Axe
|
||||||
|
{
|
||||||
|
".section weapon" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_give_weapon($deck_player);
|
||||||
|
"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Execute
|
||||||
|
{
|
||||||
|
".section buff" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_destroy($defender);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$damaged_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Arcanite Reaper
|
||||||
|
{
|
||||||
|
".section weapon" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_give_weapon($deck_player);
|
||||||
|
"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Magma Rager
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$enemy_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Ironforge Rifleman
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
def(card_s, def)
|
||||||
|
def = hsl_card($target);
|
||||||
|
if(def) {
|
||||||
|
hsl_attack_bc($attacker, def, 1)
|
||||||
|
}
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$all"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Kobold Geomancer
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$enemy_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Bloodfen Raptor
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$enemy_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Razorfen Hunter
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_summon_card($deck_player, \"CS2_boar\", cardholder)
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Stormwind Champion
|
||||||
|
{
|
||||||
|
".section attack" : {
|
||||||
|
"code" : "
|
||||||
|
hsl_attack($attacker, $defenders);
|
||||||
|
",
|
||||||
|
|
||||||
|
"target" : "$enemy_minions"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Frostwolf Warlord
|
||||||
|
{
|
||||||
|
".section battlecry" : {
|
||||||
|
"code" : "
|
||||||
|
int num_minions = hsl_board_minions_count($deck_player, $attacker);
|
||||||
|
if(num_minions > 0) {
|
||||||
|
hsl_change_health($attacker, num_minions)
|
||||||
|
hsl_change_attack($attacker, num_minions)
|
||||||
|
|
||||||
|
hsl_add_signle_attachment($player, $deck_player, $attacker, $attacker);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
|
||||||
|
"target": "$auto"
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user