Compare commits
25 Commits
Author | SHA1 | Date |
---|---|---|
Olaf Rempel | 3ea2f29ba1 | |
Olaf Rempel | 49b9cf7135 | |
Olaf Rempel | 68fea83c6f | |
Olaf Rempel | 7811f0ab16 | |
Olaf Rempel | 2fd676eb7d | |
Olaf Rempel | a19a7bee92 | |
Olaf Rempel | ab6f8ca480 | |
Olaf Rempel | 46cbeabad5 | |
Olaf Rempel | 9e6e2a4d32 | |
Olaf Rempel | 6cd4589640 | |
Olaf Rempel | 02f775d7c2 | |
Olaf Rempel | 65bc7cd5e0 | |
Olaf Rempel | 17f64ec0f9 | |
Olaf Rempel | c4df94c900 | |
Olaf Rempel | be77f19e78 | |
Olaf Rempel | bb96fb05a3 | |
Olaf Rempel | 33e97b1eaa | |
Olaf Rempel | e0b98f4756 | |
Olaf Rempel | 2e728963c7 | |
Olaf Rempel | 38542d7ddf | |
Olaf Rempel | 190be1be3c | |
Olaf Rempel | fc57caaa6d | |
Olaf Rempel | 3593290f71 | |
Olaf Rempel | 6383cfaf67 | |
Olaf Rempel | b4478bbc1e |
|
@ -0,0 +1,8 @@
|
|||
*.o
|
||||
*.d
|
||||
hlswmaster
|
||||
hlswmaster.log
|
||||
doc
|
||||
doc/*
|
||||
masterquery
|
||||
hlswmaster-ng-*.tar.gz
|
|
@ -0,0 +1,340 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) 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
|
||||
this service 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 make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. 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.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the 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 a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE 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.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 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, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
|
@ -0,0 +1,269 @@
|
|||
# Doxyfile 1.4.4
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
PROJECT_NAME = hlswmaster-ng
|
||||
PROJECT_NUMBER =
|
||||
OUTPUT_DIRECTORY = doc
|
||||
CREATE_SUBDIRS = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
USE_WINDOWS_ENCODING = NO
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF = "The $name class" \
|
||||
"The $name widget" \
|
||||
"The $name file" \
|
||||
is \
|
||||
provides \
|
||||
specifies \
|
||||
contains \
|
||||
represents \
|
||||
a \
|
||||
an \
|
||||
the
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = YES
|
||||
STRIP_FROM_PATH = /home/razor/projects/linux-c++/hlswmaster-ng/
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
DETAILS_AT_TOP = NO
|
||||
INHERIT_DOCS = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 8
|
||||
ALIASES =
|
||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
SUBGROUPING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = YES
|
||||
EXTRACT_STATIC = YES
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = YES
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_BY_SCOPE_NAME = NO
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST= YES
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = YES
|
||||
SHOW_DIRECTORIES = YES
|
||||
FILE_VERSION_FILTER =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = /home/razor/projects/linux-c++/hlswmaster-ng
|
||||
FILE_PATTERNS = *.c \
|
||||
*.cc \
|
||||
*.cxx \
|
||||
*.cpp \
|
||||
*.c++ \
|
||||
*.java \
|
||||
*.ii \
|
||||
*.ixx \
|
||||
*.ipp \
|
||||
*.i++ \
|
||||
*.inl \
|
||||
*.h \
|
||||
*.hh \
|
||||
*.hxx \
|
||||
*.hpp \
|
||||
*.h++ \
|
||||
*.idl \
|
||||
*.odl \
|
||||
*.cs \
|
||||
*.php \
|
||||
*.php3 \
|
||||
*.inc \
|
||||
*.m \
|
||||
*.mm \
|
||||
*.dox \
|
||||
*.C \
|
||||
*.CC \
|
||||
*.C++ \
|
||||
*.II \
|
||||
*.I++ \
|
||||
*.H \
|
||||
*.HH \
|
||||
*.H++ \
|
||||
*.CS \
|
||||
*.PHP \
|
||||
*.PHP3 \
|
||||
*.M \
|
||||
*.MM
|
||||
RECURSIVE = NO
|
||||
EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS = *
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to source browsing
|
||||
#---------------------------------------------------------------------------
|
||||
SOURCE_BROWSER = YES
|
||||
INLINE_SOURCES = YES
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = NO
|
||||
REFERENCES_RELATION = NO
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = NO
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the HTML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT = html
|
||||
HTML_FILE_EXTENSION = .html
|
||||
HTML_HEADER =
|
||||
HTML_FOOTER =
|
||||
HTML_STYLESHEET =
|
||||
HTML_ALIGN_MEMBERS = YES
|
||||
GENERATE_HTMLHELP = NO
|
||||
CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
GENERATE_CHI = NO
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
DISABLE_INDEX = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
GENERATE_TREEVIEW = YES
|
||||
TREEVIEW_WIDTH = 250
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_LATEX = NO
|
||||
LATEX_OUTPUT = latex
|
||||
LATEX_CMD_NAME = latex
|
||||
MAKEINDEX_CMD_NAME = makeindex
|
||||
COMPACT_LATEX = NO
|
||||
PAPER_TYPE = a4wide
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER =
|
||||
PDF_HYPERLINKS = NO
|
||||
USE_PDFLATEX = NO
|
||||
LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_RTF = NO
|
||||
RTF_OUTPUT = rtf
|
||||
COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_MAN = NO
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_LINKS = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the XML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_XML = NO
|
||||
XML_OUTPUT = xml
|
||||
XML_SCHEMA =
|
||||
XML_DTD =
|
||||
XML_PROGRAMLISTING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options for the AutoGen Definitions output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the Perl module output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_PERLMOD = NO
|
||||
PERLMOD_LATEX = NO
|
||||
PERLMOD_PRETTY = YES
|
||||
PERLMOD_MAKEVAR_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the preprocessor
|
||||
#---------------------------------------------------------------------------
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED =
|
||||
EXPAND_AS_DEFINED =
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to external references
|
||||
#---------------------------------------------------------------------------
|
||||
TAGFILES =
|
||||
GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = YES
|
||||
PERL_PATH = /usr/bin/perl
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = YES
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
GROUP_GRAPHS = YES
|
||||
UML_LOOK = NO
|
||||
TEMPLATE_RELATIONS = NO
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
CALL_GRAPH = NO
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DIRECTORY_GRAPH = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
MAX_DOT_GRAPH_WIDTH = 1024
|
||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||
MAX_DOT_GRAPH_DEPTH = 1000
|
||||
DOT_TRANSPARENT = NO
|
||||
DOT_MULTI_TARGETS = NO
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to the search engine
|
||||
#---------------------------------------------------------------------------
|
||||
SEARCHENGINE = NO
|
42
Makefile
42
Makefile
|
@ -1,22 +1,42 @@
|
|||
CFLAGS := -O2 -pipe -Wall -Wunused -Wno-deprecated
|
||||
VERSION := v1.01
|
||||
|
||||
CFLAGS := -O2 -pipe -Wall -DVERSION='"$(VERSION)"'
|
||||
CXXFLAGS := -O2 -pipe -Wall -Wunused -Wno-deprecated -DVERSION='"$(VERSION)"'
|
||||
LIBS := -lpthread
|
||||
|
||||
SRC := $(wildcard *.cpp)
|
||||
OBJS := $(SRC:.cpp=.o)
|
||||
DEPS := $(SRC:.cpp=.d)
|
||||
HLSWMASTER_SRC := config.o gameentry.o gamelist.o gameparser.o gamescanner.o \
|
||||
hlswmaster.o hlswserver.o logging.o modhelper.o modulelist.o \
|
||||
multisock.o netpkt.o socket.o timerservice.o thread.o \
|
||||
mod_d3engine.o mod_gamespy1.o mod_gamespy2.o mod_halflife.o \
|
||||
mod_q3engine.o mod_quake2.o mod_ut.o
|
||||
|
||||
all: hlswmaster
|
||||
all: hlswmaster masterquery
|
||||
|
||||
hlswmaster: $(OBJS)
|
||||
$(CXX) $(CFLAGS) $^ $(LIBS) -o $@
|
||||
hlswmaster: $(HLSWMASTER_SRC) hlswmaster.o
|
||||
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
|
||||
|
||||
masterquery: masterquery.o
|
||||
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CFLAGS) -c $< -o $@
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
%.d: %.cpp
|
||||
$(CXX) $(CFLAGS) -MM -c $< -o $@
|
||||
$(CXX) $(CXXFLAGS) -MM -c $< -o $@
|
||||
|
||||
dist: clean
|
||||
ln -s . hlswmaster-ng
|
||||
tar -czhf hlswmaster-ng-$(VERSION).tar.gz hlswmaster-ng/ \
|
||||
--exclude hlswmaster-ng/.git \
|
||||
--exclude hlswmaster-ng/.gitignore \
|
||||
--exclude hlswmaster-ng/doc \
|
||||
--exclude hlswmaster-ng/hlswmaster-ng-$(VERSION).tar.gz \
|
||||
--exclude hlswmaster-ng/hlswmaster-ng
|
||||
rm hlswmaster-ng
|
||||
|
||||
clean:
|
||||
rm -f hlswmaster *.d *.o *.log
|
||||
rm -f hlswmaster masterquery *.d *.o *.log \
|
||||
hlswmaster-ng hlswmaster-ng-$(VERSION).tar.gz
|
||||
|
||||
-include $(DEPS)
|
||||
##DEPS := $(wildcard *.cpp)
|
||||
##-include $(DEPS:.cpp=.d)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
linux HLSWMASTER-NG
|
||||
===================
|
||||
|
||||
howto use it:
|
||||
$ make all
|
||||
$ ./hlswmaster
|
161
config.cpp
161
config.cpp
|
@ -1,3 +1,22 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
@ -5,6 +24,8 @@
|
|||
#include "config.h"
|
||||
#include "logging.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
/* ------ */
|
||||
|
||||
Config::Tupel::Tupel(const char* name_, const char* value_)
|
||||
|
@ -15,8 +36,8 @@ Config::Tupel::Tupel(const char* name_, const char* value_)
|
|||
|
||||
Config::Tupel::~Tupel()
|
||||
{
|
||||
free(name);
|
||||
free(value);
|
||||
free((char*)name);
|
||||
free((char*)value);
|
||||
}
|
||||
|
||||
/* ------ */
|
||||
|
@ -31,7 +52,7 @@ Config::Section::~Section()
|
|||
while (!tupelList.isEmpty())
|
||||
delete tupelList.get();
|
||||
|
||||
free(name);
|
||||
free((char*)name);
|
||||
}
|
||||
|
||||
bool Config::Section::addTupel(const char* name, const char* value)
|
||||
|
@ -40,27 +61,27 @@ bool Config::Section::addTupel(const char* name, const char* value)
|
|||
return false;
|
||||
|
||||
Tupel* t = new Tupel(name, value);
|
||||
tupelList.addTail(t);
|
||||
|
||||
tupelList.add(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Config::Section::show() const
|
||||
void Config::Section::show()
|
||||
{
|
||||
Iterator<Tupel>* it = tupelList.createIterator();
|
||||
LogSystem::log(LOG_DEBUG, "[%s]", name);
|
||||
|
||||
LogSystem::log(LOG_INFO, "[%s]", name);
|
||||
|
||||
while (it->hasNext()) {
|
||||
Tupel* t = it->next();
|
||||
LogSystem::log(LOG_DEBUG, " %s = %s", t->name, t->value);
|
||||
LogSystem::log(LOG_INFO, " %s = %s", t->name, t->value);
|
||||
}
|
||||
|
||||
|
||||
delete it;
|
||||
}
|
||||
|
||||
char* Config::Section::getTupelValue(const char* name) const
|
||||
const char* Config::Section::getTupelValue(const char* name)
|
||||
{
|
||||
char* retval = 0;
|
||||
const char* retval = 0;
|
||||
Iterator<Tupel>* it = this->tupelList.createIterator();
|
||||
while (it->hasNext()) {
|
||||
Tupel* t = it->next();
|
||||
|
@ -69,13 +90,47 @@ char* Config::Section::getTupelValue(const char* name) const
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete it;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* ------ */
|
||||
|
||||
Config::Section::SectionIterator::SectionIterator(Section* section, const char* name)
|
||||
: nexttup(0), name(name)
|
||||
{
|
||||
it = section->tupelList.createIterator();
|
||||
}
|
||||
|
||||
Config::Section::SectionIterator::~SectionIterator()
|
||||
{
|
||||
delete it;
|
||||
}
|
||||
|
||||
bool Config::Section::SectionIterator::hasNext()
|
||||
{
|
||||
while (it->hasNext()) {
|
||||
nexttup = it->next();
|
||||
if (!strcmp(nexttup->name, name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
char* Config::Section::SectionIterator::next()
|
||||
{
|
||||
return (char*)nexttup->value;
|
||||
}
|
||||
|
||||
void Config::Section::SectionIterator::reset()
|
||||
{
|
||||
it->reset();
|
||||
nexttup = 0;
|
||||
}
|
||||
|
||||
/* ------ */
|
||||
|
||||
Config::~Config()
|
||||
{
|
||||
while (!sectionList.isEmpty())
|
||||
|
@ -85,29 +140,31 @@ Config::~Config()
|
|||
Config::Section* Config::addSection(const char* name)
|
||||
{
|
||||
Section* s = new Section(name);
|
||||
sectionList.addTail(s);
|
||||
sectionList.add(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
bool Config::parseFile(const char* name)
|
||||
{
|
||||
Config::Section* section = 0;
|
||||
Section* section = 0;
|
||||
FILE *fz;
|
||||
int i = 0;
|
||||
char *row, *tok, *tok2;
|
||||
bool ret = true;
|
||||
|
||||
if (!(row = (char*)malloc(1024))) {
|
||||
LogSystem::log(LOG_CRIT, "config_parse(): malloc()");
|
||||
|
||||
row = new char[BUFSIZE];
|
||||
if (!row) {
|
||||
LogSystem::log(LOG_ERROR, "config_parse(): out of memory()");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!(fz = fopen(name, "r"))) {
|
||||
LogSystem::log(LOG_ERROR, "config_parse(): can not open %s", name);
|
||||
delete [] row;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (fgets(row, 1024, fz)) {
|
||||
|
||||
while (fgets(row, BUFSIZE, fz)) {
|
||||
i++;
|
||||
|
||||
/* kommentar oder leere zeile */
|
||||
|
@ -119,7 +176,7 @@ bool Config::parseFile(const char* name)
|
|||
tok = strtok(row +1, " ]\n");
|
||||
section = addSection(tok);
|
||||
if (!section) {
|
||||
LogSystem::log(LOG_WARNING, "config_parse(): invalid section in row %d", i);
|
||||
LogSystem::log(LOG_WARN, "config_parse(): invalid section in row %d", i);
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
@ -127,27 +184,29 @@ bool Config::parseFile(const char* name)
|
|||
|
||||
/* option, aber es gab noch keine section */
|
||||
} else if (!section) {
|
||||
LogSystem::log(LOG_WARNING, "config_parse(): missing section in row %d", i);
|
||||
LogSystem::log(LOG_WARN, "config_parse(): missing section in row %d", i);
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* option */
|
||||
if ((tok = strtok(row, " \n")) && (tok2 = strtok(NULL, " \n"))) {
|
||||
if (!section->addTupel(tok, tok2))
|
||||
LogSystem::log(LOG_WARNING, "config_parse(): invalid row %d", i);
|
||||
if ((tok = strtok(row, " \n"))) {
|
||||
while ((tok2 = strtok(NULL, " \n"))) {
|
||||
if (!section->addTupel(tok, tok2))
|
||||
LogSystem::log(LOG_WARN, "config_parse(): invalid row %d", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fclose(fz);
|
||||
free(row);
|
||||
|
||||
delete [] row;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Config::show() const
|
||||
void Config::show()
|
||||
{
|
||||
LogSystem::log(LOG_DEBUG, "Config Dump:");
|
||||
LogSystem::log(LOG_INFO, "Config Dump:");
|
||||
Iterator<Section>* it = sectionList.createIterator();
|
||||
while (it->hasNext())
|
||||
it->next()->show();
|
||||
|
@ -155,15 +214,15 @@ void Config::show() const
|
|||
delete it;
|
||||
}
|
||||
|
||||
char* Config::getParameter(const char* section, const char* option) const
|
||||
Config::Section* Config::getSection(const char* name)
|
||||
{
|
||||
char* retval = 0;
|
||||
|
||||
Section* retval = 0;
|
||||
|
||||
Iterator<Section>* it = sectionList.createIterator();
|
||||
while (it->hasNext()) {
|
||||
Section* s = it->next();
|
||||
if (!strcmp(s->name, section)) {
|
||||
retval = s->getTupelValue(option);
|
||||
if (!strcmp(s->name, name)) {
|
||||
retval = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -172,9 +231,15 @@ char* Config::getParameter(const char* section, const char* option) const
|
|||
return retval;
|
||||
}
|
||||
|
||||
char* Config::getString(const char* section, const char* option, char* def) const
|
||||
const char* Config::getParameter(const char* section, const char* option)
|
||||
{
|
||||
char* retval = getParameter(section, option);
|
||||
Section* s = getSection(section);
|
||||
return s ? s->getTupelValue(option) : 0;
|
||||
}
|
||||
|
||||
const char* Config::getString(const char* section, const char* option, char* def)
|
||||
{
|
||||
const char* retval = getParameter(section, option);
|
||||
if (!retval) {
|
||||
LogSystem::log(LOG_NOTICE,
|
||||
"Config: [%s:%s] not found => using '%s'",
|
||||
|
@ -184,9 +249,9 @@ char* Config::getString(const char* section, const char* option, char* def) cons
|
|||
return retval;
|
||||
}
|
||||
|
||||
int Config::getInteger(const char* section, const char* option, int def) const
|
||||
int Config::getInteger(const char* section, const char* option, int def)
|
||||
{
|
||||
char* retval = getParameter(section, option);
|
||||
const char* retval = getParameter(section, option);
|
||||
if (!retval) {
|
||||
LogSystem::log(LOG_NOTICE,
|
||||
"Config: [%s:%s] not found => using '%d'",
|
||||
|
@ -195,3 +260,17 @@ int Config::getInteger(const char* section, const char* option, int def) const
|
|||
}
|
||||
return atoi(retval);
|
||||
}
|
||||
|
||||
Iterator<char>* Config::createIterator(const char* section, const char* name)
|
||||
{
|
||||
Section* s = getSection(section);
|
||||
if (!s) {
|
||||
LogSystem::log(LOG_NOTICE,"Config: [%s:%s] not found",
|
||||
section, name);
|
||||
|
||||
return new NullIterator<char>();
|
||||
|
||||
} else {
|
||||
return new Config::Section::SectionIterator(s, name);
|
||||
}
|
||||
}
|
||||
|
|
47
config.h
47
config.h
|
@ -8,38 +8,55 @@ public:
|
|||
~Config();
|
||||
|
||||
bool parseFile(const char* name);
|
||||
void show() const;
|
||||
void show();
|
||||
|
||||
char* getParameter(const char* section, const char* name) const;
|
||||
char* getString(const char* section, const char* name, char* def) const;
|
||||
int getInteger(const char* section, const char* name, int def) const;
|
||||
const char* getParameter(const char* section, const char* name);
|
||||
const char* getString(const char* section, const char* name, char* def);
|
||||
int getInteger(const char* section, const char* name, int def);
|
||||
|
||||
Iterator<char>* createIterator(const char* section, const char* name);
|
||||
|
||||
private:
|
||||
class Tupel {
|
||||
public:
|
||||
class Tupel : private ListEntry<Tupel> {
|
||||
public:
|
||||
Tupel(const char* name, const char* value);
|
||||
~Tupel();
|
||||
|
||||
char* name;
|
||||
char* value;
|
||||
const char* name;
|
||||
const char* value;
|
||||
};
|
||||
|
||||
class Section {
|
||||
|
||||
class Section : private ListEntry<Section> {
|
||||
public:
|
||||
class SectionIterator : public Iterator<char> {
|
||||
public:
|
||||
SectionIterator(Section* section, const char* name);
|
||||
~SectionIterator();
|
||||
bool hasNext();
|
||||
char* next();
|
||||
void remove() {}
|
||||
void reset();
|
||||
|
||||
private:
|
||||
Iterator<Tupel>* it;
|
||||
Tupel* nexttup;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
Section(const char* name);
|
||||
~Section();
|
||||
|
||||
bool addTupel(const char* name, const char* option);
|
||||
char* getTupelValue(const char* name) const;
|
||||
void show() const;
|
||||
|
||||
char* name;
|
||||
const char* getTupelValue(const char* name);
|
||||
void show();
|
||||
|
||||
const char* name;
|
||||
|
||||
private:
|
||||
List<Tupel> tupelList;
|
||||
};
|
||||
|
||||
Section* addSection(const char* name);
|
||||
Section* getSection(const char* name);
|
||||
|
||||
List<Section> sectionList;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "gameentry.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "gameentry.h"
|
||||
|
||||
GameEntry::GameEntry(int gameid, struct in_addr *addr, int port1, int port2)
|
||||
: port1(port1), port2(port2), gameid(gameid)
|
||||
{
|
||||
memcpy(&this->addr, addr, sizeof(this->addr));
|
||||
|
||||
if (port2 != 0) {
|
||||
this->port2 = this->port1;
|
||||
this->port1 = port2;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
int GameEntry::compare(const GameEntry* ge)
|
||||
{
|
||||
if (this->addr.s_addr > ge->addr.s_addr)
|
||||
return -1;
|
||||
|
||||
if (this->addr.s_addr < ge->addr.s_addr)
|
||||
return 1;
|
||||
|
||||
if (this->port1 > ge->port1)
|
||||
return -1;
|
||||
|
||||
if (this->port1 < ge->port1)
|
||||
return 1;
|
||||
|
||||
// only compare IP:port
|
||||
// gameid and port2 are useless
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GameEntry::hash(int max)
|
||||
{
|
||||
unsigned int hash = 0x12345678;
|
||||
|
||||
// IP
|
||||
hash = ((hash<<5) ^ (hash>>27)) ^ ((addr.s_addr>>0) & 0xFF);
|
||||
hash = ((hash<<5) ^ (hash>>27)) ^ ((addr.s_addr>>8) & 0xFF);
|
||||
hash = ((hash<<5) ^ (hash>>27)) ^ ((addr.s_addr>>16) & 0xFF);
|
||||
hash = ((hash<<5) ^ (hash>>27)) ^ ((addr.s_addr>>24) & 0xFF);
|
||||
|
||||
// port
|
||||
hash = ((hash<<5) ^ (hash>>27)) ^ ((port1>>0) & 0xFF);
|
||||
hash = ((hash<<5) ^ (hash>>27)) ^ ((port1>>8) & 0xFF);
|
||||
|
||||
return hash % max;
|
||||
}
|
||||
|
||||
void GameEntry::update()
|
||||
{
|
||||
modtime = time(NULL);
|
||||
}
|
||||
|
||||
int GameEntry::show(char* buf, int size)
|
||||
{
|
||||
return snprintf(buf, size, "(%2d:%15s:%5d:%5d)",
|
||||
this->gameid, inet_ntoa(this->addr),
|
||||
this->port1, this->port2);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef _GAMEENTRY_H_
|
||||
#define _GAMEENTRY_H_
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "list.h"
|
||||
|
||||
class GameEntry : private ListEntry<GameEntry> {
|
||||
public:
|
||||
GameEntry(int gameid, struct in_addr *addr, int port1, int port2);
|
||||
~GameEntry() {}
|
||||
|
||||
int compare(const GameEntry* ge);
|
||||
int hash(int max);
|
||||
void update();
|
||||
|
||||
int show(char* buf, int size);
|
||||
|
||||
struct in_addr addr;
|
||||
int port1;
|
||||
int port2;
|
||||
int gameid;
|
||||
long modtime;
|
||||
|
||||
protected:
|
||||
GameEntry(const GameEntry& ge);
|
||||
GameEntry& operator=(const GameEntry& ge);
|
||||
};
|
||||
|
||||
#endif // _GAMEENTRY_H_
|
|
@ -0,0 +1,149 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "gamelist.h"
|
||||
#include "logging.h"
|
||||
|
||||
#define DEFAULT_TIMEOUT 180
|
||||
|
||||
GameList::GameList(Config& conf)
|
||||
{
|
||||
timeout = conf.getInteger("global", "game_timeout", DEFAULT_TIMEOUT);
|
||||
TimerService::registerTimer(new Timer(new CleanupEvent(*this), timeout));
|
||||
}
|
||||
|
||||
GameList::~GameList()
|
||||
{
|
||||
Iterator<GameEntry>* it = createIterator();
|
||||
while (it->hasNext())
|
||||
delete it->next();
|
||||
|
||||
delete it;
|
||||
}
|
||||
|
||||
void GameList::cleanup()
|
||||
{
|
||||
long now = time(NULL);
|
||||
|
||||
Iterator<GameEntry>* it = createIterator();
|
||||
while (it->hasNext()) {
|
||||
GameEntry* ge = it->next();
|
||||
|
||||
if (ge->modtime + timeout <= now) {
|
||||
it->remove();
|
||||
|
||||
char buf[64];
|
||||
ge->show(buf, sizeof(buf));
|
||||
LogSystem::log(LOG_NOTICE, "Game Timeout: %s", buf);
|
||||
delete ge;
|
||||
}
|
||||
}
|
||||
delete it;
|
||||
}
|
||||
|
||||
void GameList::addGame(int gameid, NetPkt* pkt, int port2)
|
||||
{
|
||||
addGame(gameid, &pkt->getAddress()->sin_addr, pkt->getPort(), port2);
|
||||
}
|
||||
|
||||
void GameList::addGame(int gameid, struct in_addr *addr, int port1, int port2)
|
||||
{
|
||||
GameEntry* ge = new GameEntry(gameid, addr, port1, port2);
|
||||
int hash = ge->hash(MAX_BUCKETS);
|
||||
bool found = false;
|
||||
|
||||
Iterator<GameEntry>* it = buckets[hash].createIterator();
|
||||
while (it->hasNext()) {
|
||||
GameEntry* tmp = it->next();
|
||||
if (ge->compare(tmp) == 0) {
|
||||
tmp->update();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
char buf[64];
|
||||
ge->show(buf, sizeof(buf));
|
||||
LogSystem::log(LOG_NOTICE, "Adding Game : %s", buf);
|
||||
|
||||
buckets[hash].add(ge);
|
||||
|
||||
} else {
|
||||
delete ge;
|
||||
}
|
||||
|
||||
// it holds the lock!
|
||||
delete it;
|
||||
}
|
||||
|
||||
Iterator<GameEntry>* GameList::createIterator()
|
||||
{
|
||||
return new GameListIterator(this);
|
||||
}
|
||||
|
||||
|
||||
GameList::GameListIterator::GameListIterator(GameList* gl)
|
||||
: gl(gl), it(0)
|
||||
{
|
||||
gl->mutex.lock();
|
||||
reset();
|
||||
}
|
||||
|
||||
GameList::GameListIterator::~GameListIterator()
|
||||
{
|
||||
delete it;
|
||||
gl->mutex.unlock();
|
||||
}
|
||||
|
||||
bool GameList::GameListIterator::hasNext()
|
||||
{
|
||||
if (it->hasNext())
|
||||
return true;
|
||||
|
||||
while (bucket < MAX_BUCKETS -1) {
|
||||
delete it;
|
||||
bucket++;
|
||||
|
||||
it = gl->buckets[bucket].createIterator();
|
||||
if (it->hasNext())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
GameEntry* GameList::GameListIterator::next()
|
||||
{
|
||||
return it->next();
|
||||
}
|
||||
|
||||
void GameList::GameListIterator::remove()
|
||||
{
|
||||
it->remove();
|
||||
}
|
||||
|
||||
void GameList::GameListIterator::reset()
|
||||
{
|
||||
if (it != NULL)
|
||||
delete it;
|
||||
|
||||
bucket = 0;
|
||||
it = gl->buckets[bucket].createIterator();
|
||||
}
|
68
gamelist.h
68
gamelist.h
|
@ -1,31 +1,65 @@
|
|||
#ifndef _GAMELIST_H_
|
||||
#define _GAMELIST_H_
|
||||
|
||||
class GameEntry {
|
||||
public:
|
||||
GameEntry();
|
||||
~GameEntry();
|
||||
#include <netinet/in.h>
|
||||
|
||||
protected:
|
||||
GameEntry(const GameEntry& ge);
|
||||
GameEntry& operator=(const GameEntry& ge);
|
||||
|
||||
private:
|
||||
struct in_addr addr;
|
||||
int port1;
|
||||
int port2;
|
||||
int gameid;
|
||||
};
|
||||
#include "config.h"
|
||||
#include "netpkt.h"
|
||||
#include "gameentry.h"
|
||||
#include "timerservice.h"
|
||||
#include "list.h"
|
||||
#include "mutex.h"
|
||||
|
||||
// 127 is prime!
|
||||
#define MAX_BUCKETS 127
|
||||
|
||||
class GameList {
|
||||
public:
|
||||
virtual ~GameList() {};
|
||||
GameList(Config& conf);
|
||||
~GameList();
|
||||
|
||||
virtual void cleanup() {};
|
||||
void cleanup();
|
||||
void addGame(int gameid, NetPkt* pkt, int port2 = 0);
|
||||
void addGame(int gameid, struct in_addr *addr, int port1, int port2 = 0);
|
||||
Iterator<GameEntry>* createIterator();
|
||||
|
||||
protected:
|
||||
GameList() {}
|
||||
GameList(const GameList& gl);
|
||||
GameList& operator=(const GameList& gl);
|
||||
|
||||
private:
|
||||
class CleanupEvent : public Event {
|
||||
public:
|
||||
CleanupEvent(GameList& gl) : gl(gl) {}
|
||||
~CleanupEvent() {}
|
||||
void execute() { gl.cleanup(); }
|
||||
|
||||
private:
|
||||
GameList& gl;
|
||||
};
|
||||
|
||||
class GameListIterator : public Iterator<GameEntry> {
|
||||
public:
|
||||
GameListIterator(GameList* gl);
|
||||
~GameListIterator();
|
||||
|
||||
bool hasNext();
|
||||
GameEntry* next();
|
||||
void remove();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
GameList* gl;
|
||||
Iterator<GameEntry>* it;
|
||||
int bucket;
|
||||
};
|
||||
|
||||
Mutex mutex;
|
||||
List<GameEntry> buckets[MAX_BUCKETS];
|
||||
|
||||
int timeout;
|
||||
|
||||
friend class GameList::GameListIterator;
|
||||
};
|
||||
|
||||
#endif // _GAMELIST_H_
|
||||
|
|
|
@ -1,42 +1,63 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "gameparser.h"
|
||||
#include "logging.h"
|
||||
#include "netpkt.h"
|
||||
#include "gameparser.h"
|
||||
|
||||
#define DEFAULT_TIMEOUT 180
|
||||
|
||||
GameParser::GameParser(Config& conf, RecvQueue& rxQueue, ModuleList& modList)
|
||||
: rxQueue(rxQueue), modList(modList)
|
||||
{
|
||||
int interval = conf.getInteger("global", "game_timeout", DEFAULT_TIMEOUT);
|
||||
TimerService::registerTimer(new Timer(new CleanupEvent(this), interval));
|
||||
}
|
||||
|
||||
GameParser::~GameParser()
|
||||
GameParser::GameParser(GameScanner& scanner, ModuleList& modList, GameList& gameList)
|
||||
: scanner(scanner), modList(modList), gameList(gameList)
|
||||
{
|
||||
}
|
||||
|
||||
int GameParser::execute(void* arg)
|
||||
{
|
||||
while (1) {
|
||||
NetPkt* pkt = rxQueue.getPkt();
|
||||
int ret = modList.parse(pkt, this);
|
||||
switch (ret) {
|
||||
case PKT_REJECT:
|
||||
char buf[64];
|
||||
pkt->show(buf, sizeof(buf));
|
||||
LogSystem::log(LOG_DEBUG, "unknown Packet: %s", buf);
|
||||
NetPkt* pkt;
|
||||
char buf[64], *p;
|
||||
int ret;
|
||||
|
||||
case PKT_ACCEPT:
|
||||
while (1) {
|
||||
pkt = scanner.getPkt();
|
||||
ret = modList.parse(pkt, &gameList);
|
||||
|
||||
switch (ret) {
|
||||
case PARSE_ACCEPT_FAKE:
|
||||
pkt->show(buf, sizeof(buf));
|
||||
LogSystem::log(LOG_NOTICE, "not supported Game: %s", buf);
|
||||
|
||||
case PARSE_ACCEPT:
|
||||
delete pkt;
|
||||
|
||||
case PKT_ACCEPT_FREED:
|
||||
|
||||
case PARSE_ACCEPT_FREED:
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
case PARSE_REJECT:
|
||||
pkt->show(buf, sizeof(buf));
|
||||
LogSystem::log(LOG_NOTICE, "unknown Packet: %s", buf);
|
||||
|
||||
p = pkt->showfull();
|
||||
LogSystem::log(LOG_DEBUG, "%s", p);
|
||||
delete [] p;
|
||||
delete pkt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GameParser::cleanup()
|
||||
{
|
||||
LogSystem::log(LOG_DEBUG, "GameParser::cleanup()");
|
||||
}
|
||||
|
|
29
gameparser.h
29
gameparser.h
|
@ -1,39 +1,26 @@
|
|||
#ifndef _GAMEPARSER_H_
|
||||
#define _GAMEPARSER_H_
|
||||
|
||||
#include "gamelist.h"
|
||||
#include "thread.h"
|
||||
#include "config.h"
|
||||
#include "recvqueue.h"
|
||||
#include "gamescanner.h"
|
||||
#include "modulelist.h"
|
||||
#include "timerservice.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class GameParser : public GameList, public Thread {
|
||||
class GameParser : public Thread {
|
||||
public:
|
||||
GameParser(Config& conf, RecvQueue& rxQueue, ModuleList& modlist);
|
||||
~GameParser();
|
||||
|
||||
GameParser(GameScanner& scanner, ModuleList& modlist, GameList& gameList);
|
||||
~GameParser() {};
|
||||
|
||||
int execute(void* arg);
|
||||
|
||||
void cleanup();
|
||||
|
||||
protected:
|
||||
GameParser(const GameParser& rp);
|
||||
GameParser& operator=(const GameParser& rp);
|
||||
|
||||
private:
|
||||
class CleanupEvent : public Command {
|
||||
public:
|
||||
CleanupEvent(GameList* sl) : sl(sl) {}
|
||||
~CleanupEvent() {}
|
||||
void execute() { sl->cleanup(); }
|
||||
|
||||
private:
|
||||
GameList* sl;
|
||||
};
|
||||
|
||||
RecvQueue& rxQueue;
|
||||
GameScanner& scanner;
|
||||
ModuleList& modList;
|
||||
GameList& gameList;
|
||||
};
|
||||
|
||||
#endif // _GAMEPARSER_H_
|
||||
|
|
|
@ -1,18 +1,33 @@
|
|||
#include "logging.h"
|
||||
#include "timerservice.h"
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "gamescanner.h"
|
||||
|
||||
#define DEFAULT_INTERVAL 30
|
||||
#define DEFAULT_SCAN_INTERVAL 30
|
||||
|
||||
GameScanner::GameScanner(Config& conf, ModuleList& modList)
|
||||
: modList(modList)
|
||||
{
|
||||
msock = new MultiSock(conf);
|
||||
pktCount = new Semaphore(0);
|
||||
|
||||
int interval = conf.getInteger("global", "scan_interval", DEFAULT_INTERVAL);
|
||||
TimerService::registerTimer(new Timer(new ScanEvent(this), interval));
|
||||
int interval = conf.getInteger("global", "scan_interval", DEFAULT_SCAN_INTERVAL);
|
||||
TimerService::registerTimer(new Timer(new ScanEvent(*this), interval));
|
||||
}
|
||||
|
||||
GameScanner::~GameScanner()
|
||||
|
@ -20,19 +35,16 @@ GameScanner::~GameScanner()
|
|||
while (!pktList.isEmpty())
|
||||
delete pktList.get();
|
||||
|
||||
delete pktCount;
|
||||
delete msock;
|
||||
}
|
||||
|
||||
int GameScanner::execute(void* arg)
|
||||
{
|
||||
while (1) {
|
||||
int fd = msock->getRecvSocket();
|
||||
NetPkt* pkt = NetPkt::createFromSocket(fd);
|
||||
|
||||
NetPkt* pkt = msock->recv();
|
||||
if (pkt != NULL) {
|
||||
pktList.addTail(pkt);
|
||||
pktCount->post();
|
||||
pktList.add(pkt);
|
||||
pktCount.post();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -45,6 +57,6 @@ void GameScanner::scan()
|
|||
|
||||
NetPkt* GameScanner::getPkt()
|
||||
{
|
||||
pktCount->wait();
|
||||
pktCount.wait();
|
||||
return pktList.get();
|
||||
}
|
||||
|
|
|
@ -1,49 +1,45 @@
|
|||
#ifndef _GAMESCANNER_H_
|
||||
#define _GAMESCANNER_H_
|
||||
|
||||
#include "recvqueue.h"
|
||||
#include "thread.h"
|
||||
#include "config.h"
|
||||
#include "modulelist.h"
|
||||
|
||||
#include "timerservice.h"
|
||||
#include "multisock.h"
|
||||
#include "semaphore.h"
|
||||
#include "list.h"
|
||||
#include "netpkt.h"
|
||||
|
||||
#include "timerservice.h"
|
||||
|
||||
class GameScanner : public RecvQueue, public Thread {
|
||||
class GameScanner : public Thread {
|
||||
public:
|
||||
GameScanner(Config& conf, ModuleList& modList);
|
||||
~GameScanner();
|
||||
|
||||
void scan();
|
||||
|
||||
NetPkt* getPkt();
|
||||
|
||||
int execute(void* arg);
|
||||
void scan();
|
||||
|
||||
NetPkt* getPkt();
|
||||
|
||||
protected:
|
||||
GameScanner(const GameScanner& hs);
|
||||
GameScanner& operator=(const GameScanner& hs);
|
||||
|
||||
private:
|
||||
class ScanEvent : public Command {
|
||||
class ScanEvent : public Event {
|
||||
public:
|
||||
ScanEvent(GameScanner* gs) : gs(gs) {}
|
||||
ScanEvent(GameScanner& gs) : gs(gs) {}
|
||||
~ScanEvent() {}
|
||||
void execute() { gs->scan(); }
|
||||
|
||||
void execute() { gs.scan(); }
|
||||
|
||||
private:
|
||||
GameScanner* gs;
|
||||
};
|
||||
GameScanner& gs;
|
||||
};
|
||||
|
||||
ModuleList& modList;
|
||||
MultiSock* msock;
|
||||
Semaphore* pktCount;
|
||||
List<NetPkt> pktList;
|
||||
|
||||
Semaphore pktCount;
|
||||
LockedList<NetPkt> pktList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // _SCANNER_H_
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
scan_port 7130
|
||||
|
||||
# broadcast scan every X seconds
|
||||
scan_interval 10
|
||||
scan_interval 60
|
||||
|
||||
# use this interface(s)
|
||||
scan_deny_iface
|
||||
|
||||
# server timeout after X seconds
|
||||
game_timeout 30
|
||||
game_timeout 180
|
||||
|
||||
# master answers with this source IP
|
||||
master_ip 0.0.0.0
|
||||
|
||||
# rebuild master list every X seconds
|
||||
rebuild_interval 5
|
||||
|
||||
# logging
|
||||
logfile hlswmaster.log
|
||||
logprio 7
|
||||
logprio DEBUG
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -5,16 +24,24 @@
|
|||
|
||||
#include "logging.h"
|
||||
#include "config.h"
|
||||
#include "modulelist.h"
|
||||
#include "gamelist.h"
|
||||
#include "gamescanner.h"
|
||||
#include "gameparser.h"
|
||||
#include "hlswserver.h"
|
||||
#include "timerservice.h"
|
||||
#include "modulelist.h"
|
||||
|
||||
#include "mod_example.h"
|
||||
#include "mod_d3engine.h"
|
||||
#include "mod_gamespy1.h"
|
||||
#include "mod_gamespy2.h"
|
||||
#include "mod_halflife.h"
|
||||
#include "mod_q3engine.h"
|
||||
#include "mod_quake2.h"
|
||||
#include "mod_ut.h"
|
||||
|
||||
#define DEFAULT_CONFIG "hlswmaster.conf"
|
||||
#define DEFAULT_LOGFILE "hlswmaster.log"
|
||||
#define DEFAULT_LOGPRIO "WARN"
|
||||
|
||||
static struct option opts[] = {
|
||||
{"config", 1, 0, 'c'},
|
||||
|
@ -25,7 +52,7 @@ static struct option opts[] = {
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
LogSystem::init(LOG_DEBUG, new StdErrLog());
|
||||
LogSystem::init(DEFAULT_LOGPRIO, new StdErrLog());
|
||||
|
||||
int arg = 0, code = 0, debug = 0;
|
||||
char *configfile = DEFAULT_CONFIG;
|
||||
|
@ -59,29 +86,43 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Config conf;
|
||||
conf.parseFile(configfile);
|
||||
|
||||
// char* logfile = conf.getString("global", "logfile", DEFAULT_LOGFILE);
|
||||
// int logprio = conf.getInteger("global", "logprio", LOG_NOTICE);
|
||||
// LogSystem::init(logprio, new FileLog(logfile));
|
||||
|
||||
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng startup");
|
||||
// conf.show();
|
||||
const char* logfile = conf.getString("global", "logfile", DEFAULT_LOGFILE);
|
||||
const char* logprio = conf.getString("global", "logprio", DEFAULT_LOGPRIO);
|
||||
if (!debug) {
|
||||
LogSystem::init(logprio, new FileLog(logfile));
|
||||
daemon(0, 0);
|
||||
} else {
|
||||
LogSystem::init(logprio, new StdErrLog());
|
||||
}
|
||||
|
||||
ModuleList modList;
|
||||
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng %s startup (pid:%d)", VERSION, getpid());
|
||||
conf.show();
|
||||
|
||||
ModuleList modList(conf);
|
||||
GameList gameList(conf);
|
||||
|
||||
GameScanner scanner(conf, modList);
|
||||
GameParser parser(conf, scanner, modList);
|
||||
HlswServer server(conf, parser);
|
||||
GameParser parser(scanner, modList, gameList);
|
||||
HlswServer server(conf, gameList);
|
||||
|
||||
modList.reg(new ModD3Engine());
|
||||
modList.reg(new ModGameSpy1());
|
||||
modList.reg(new ModGameSpy2());
|
||||
modList.reg(new ModHalfLife());
|
||||
modList.reg(new ModQ3Engine());
|
||||
modList.reg(new ModQuake2());
|
||||
modList.reg(new ModUT());
|
||||
|
||||
modList.reg(new ModExample(conf));
|
||||
|
||||
server.start();
|
||||
parser.start();
|
||||
scanner.start();
|
||||
|
||||
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng running...");
|
||||
|
||||
while (1) {
|
||||
TimerService::checkTimers();
|
||||
usleep(500000);
|
||||
|
@ -90,12 +131,12 @@ int main(int argc, char *argv[])
|
|||
LogSystem::log(LOG_CRIT, "Scanner aborted!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!parser.isRunning()) {
|
||||
LogSystem::log(LOG_CRIT, "RecvParser aborted!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!server.isRunning()) {
|
||||
LogSystem::log(LOG_CRIT, "HlswServer aborted!");
|
||||
break;
|
||||
|
|
138
hlswserver.cpp
138
hlswserver.cpp
|
@ -1,3 +1,22 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -5,74 +24,107 @@
|
|||
#include <netinet/ip.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "logging.h"
|
||||
#include "hlswserver.h"
|
||||
#include "logging.h"
|
||||
|
||||
static const char hlsw_header[] = "\xFF\xFF\xFF\xFFHLSWLANSEARCH";
|
||||
|
||||
struct hlsw_entry {
|
||||
uint16_t gameid;
|
||||
uint32_t ip;
|
||||
uint16_t port1;
|
||||
uint16_t port2;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define HLSW_HEADER "\xFF\xFF\xFF\xFFHLSWLANSEARCH\x00"
|
||||
#define HLSW_HEADER_LEN 0x12
|
||||
#define HLSW_MASTER_PORT 7140
|
||||
#define HLSW_MAX_PACKET_SIZE (sizeof(hlsw_header) + 140 * sizeof(struct hlsw_entry))
|
||||
#define DEFAULT_REBUILD_INTERVAL 5
|
||||
|
||||
HlswServer::HlswServer(Config& conf, GameList& slist)
|
||||
HlswServer::HlswServer(Config& conf, GameList& glist)
|
||||
{
|
||||
struct sockaddr_in dst;
|
||||
char *ip;
|
||||
|
||||
if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
LogSystem::log(LOG_CRIT, "HlswServer(): socket()");
|
||||
return;
|
||||
}
|
||||
|
||||
ip = conf.getString("global", "master_ip", "0.0.0.0");
|
||||
const char *ip = conf.getString("global", "master_ip", "0.0.0.0");
|
||||
LogSystem::log(LOG_NOTICE, "HlswServer listen on %s:%d", ip, HLSW_MASTER_PORT);
|
||||
|
||||
struct sockaddr_in dst;
|
||||
dst.sin_family = AF_INET;
|
||||
dst.sin_port = htons(HLSW_MASTER_PORT);
|
||||
inet_aton(ip, &dst.sin_addr);
|
||||
socket = Socket::createSocket(&dst);
|
||||
|
||||
if (bind(sock, (struct sockaddr *)&dst, sizeof(dst)) < 0) {
|
||||
LogSystem::log(LOG_WARNING, "HlswServer(): bind()");
|
||||
return;
|
||||
}
|
||||
int interval = conf.getInteger("global", "rebuild_interval", DEFAULT_REBUILD_INTERVAL);
|
||||
TimerService::registerTimer(new Timer(new RebuildEvent(*this, glist), interval));
|
||||
|
||||
out = new HlswPacket();
|
||||
pktlist = new List<NetPkt>();
|
||||
}
|
||||
|
||||
HlswServer::~HlswServer()
|
||||
{
|
||||
close(sock);
|
||||
while (!pktlist->isEmpty())
|
||||
delete pktlist->get();
|
||||
|
||||
delete pktlist;
|
||||
delete socket;
|
||||
}
|
||||
|
||||
int HlswServer::execute(void* arg)
|
||||
{
|
||||
struct sockaddr_in src;
|
||||
unsigned char buf[32];
|
||||
socklen_t len;
|
||||
int ret;
|
||||
|
||||
while (1) {
|
||||
/* auf clientanfrage warten */
|
||||
len = sizeof(src);
|
||||
ret = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&src, &len);
|
||||
if (ret != HLSW_HEADER_LEN) {
|
||||
LogSystem::log(LOG_WARNING, "HlswServer: invalid packet");
|
||||
NetPkt* pkt = socket->recv();
|
||||
if (!pkt->compare(0, hlsw_header, strlen(hlsw_header))) {
|
||||
LogSystem::log(LOG_NOTICE, "HlswServer: not a hlsw packet");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* testen ob es sich um ein HLSW anforderung handelt */
|
||||
if (memcmp(buf, HLSW_HEADER, HLSW_HEADER_LEN)) {
|
||||
LogSystem::log(LOG_WARNING, "HlswServer: not a hlsw packet");
|
||||
continue;
|
||||
}
|
||||
mutex.lock();
|
||||
Iterator<NetPkt>* it = pktlist->createIterator();
|
||||
while (it->hasNext())
|
||||
socket->sendto(it->next(), pkt->getAddress());
|
||||
|
||||
if (out != NULL && out->count > 0) {
|
||||
HlswPacket* pkt;
|
||||
for (pkt = out; pkt != NULL; pkt = pkt->next) {
|
||||
sendto(sock, pkt->data, pkt->getSize(), 0,
|
||||
(struct sockaddr *)&src, sizeof(src));
|
||||
}
|
||||
}
|
||||
delete it;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HlswServer::rebuild(GameList& glist) {
|
||||
List<NetPkt>* newlist = new List<NetPkt>();
|
||||
|
||||
// header
|
||||
NetPkt* pkt = new NetPkt(HLSW_MAX_PACKET_SIZE);
|
||||
pkt->append(hlsw_header, sizeof(hlsw_header));
|
||||
newlist->add(pkt);
|
||||
|
||||
Iterator<GameEntry>* it = glist.createIterator();
|
||||
while (it->hasNext()) {
|
||||
NetPkt* last = newlist->peekTail();
|
||||
if (last->getSize() == HLSW_MAX_PACKET_SIZE) {
|
||||
last = new NetPkt(HLSW_MAX_PACKET_SIZE);
|
||||
last->append(hlsw_header, sizeof(hlsw_header));
|
||||
newlist->add(last);
|
||||
}
|
||||
|
||||
addGame(last, it->next());
|
||||
}
|
||||
delete it;
|
||||
|
||||
mutex.lock();
|
||||
List<NetPkt>* oldlist = pktlist;
|
||||
pktlist = newlist;
|
||||
mutex.unlock();
|
||||
|
||||
while (!oldlist->isEmpty())
|
||||
delete oldlist->get();
|
||||
|
||||
delete oldlist;
|
||||
}
|
||||
|
||||
void HlswServer::addGame(NetPkt* pkt, GameEntry* entry)
|
||||
{
|
||||
struct hlsw_entry tmp;
|
||||
tmp.gameid = entry->gameid;
|
||||
tmp.ip = entry->addr.s_addr;
|
||||
tmp.port1 = entry->port1;
|
||||
tmp.port2 = entry->port2;
|
||||
|
||||
pkt->append((char*)&tmp, sizeof(tmp));
|
||||
}
|
||||
|
|
37
hlswserver.h
37
hlswserver.h
|
@ -6,41 +6,40 @@
|
|||
#include "thread.h"
|
||||
#include "config.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
#include "timerservice.h"
|
||||
#include "netpkt.h"
|
||||
#include "socket.h"
|
||||
#include "mutex.h"
|
||||
|
||||
class HlswServer : public Thread {
|
||||
public:
|
||||
HlswServer(Config& conf, GameList& slist);
|
||||
HlswServer(Config& conf, GameList& glist);
|
||||
~HlswServer();
|
||||
|
||||
int execute(void* arg);
|
||||
void rebuild(GameList& gl);
|
||||
|
||||
protected:
|
||||
HlswServer(const HlswServer& hs);
|
||||
HlswServer& operator=(const HlswServer& hs);
|
||||
|
||||
private:
|
||||
class HlswPacket {
|
||||
class RebuildEvent : public Event {
|
||||
public:
|
||||
HlswPacket() : next(0), count(0)
|
||||
{
|
||||
memset(data, 0, sizeof(data));
|
||||
}
|
||||
RebuildEvent(HlswServer& hs, GameList& gl) : hs(hs), gl(gl) {}
|
||||
~RebuildEvent() {}
|
||||
void execute() { hs.rebuild(gl); }
|
||||
|
||||
int getSize()
|
||||
{
|
||||
return 12 + count * 10;
|
||||
}
|
||||
|
||||
void addGame(void* ptr) {}
|
||||
|
||||
HlswPacket* next;
|
||||
int count;
|
||||
char data[1412];
|
||||
private:
|
||||
HlswServer& hs;
|
||||
GameList& gl;
|
||||
};
|
||||
|
||||
HlswPacket* out;
|
||||
int sock;
|
||||
void addGame(NetPkt* pkt, GameEntry* entry);
|
||||
|
||||
List<NetPkt>* pktlist;
|
||||
Mutex mutex;
|
||||
Socket* socket;
|
||||
};
|
||||
|
||||
#endif // _HLSWSERVER_H_
|
||||
|
|
320
list.h
320
list.h
|
@ -6,77 +6,88 @@
|
|||
template <class T>
|
||||
class Iterator {
|
||||
public:
|
||||
virtual ~Iterator() {}
|
||||
virtual bool hasNext() const =0;
|
||||
virtual T* next() =0;
|
||||
virtual ~Iterator() {}
|
||||
virtual bool hasNext() =0;
|
||||
virtual T* next() =0;
|
||||
virtual void remove() =0;
|
||||
virtual void reset() =0;
|
||||
|
||||
protected:
|
||||
Iterator<T>() {}
|
||||
Iterator<T>(const Iterator<T>& it);
|
||||
Iterator<T>& operator=(const Iterator<T>& it);
|
||||
Iterator() {}
|
||||
Iterator(const Iterator& it);
|
||||
Iterator& operator=(const Iterator& it);
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class NullIterator : public Iterator<T> {
|
||||
public:
|
||||
NullIterator() {}
|
||||
virtual ~NullIterator() {}
|
||||
virtual bool hasNext() { return false; }
|
||||
virtual T* next() { return NULL; }
|
||||
virtual void remove() {}
|
||||
virtual void reset() {}
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class ListEntry;
|
||||
|
||||
|
||||
template <class T>
|
||||
class ListIterator;
|
||||
|
||||
|
||||
template <class T>
|
||||
class List {
|
||||
friend class ListIterator<T>;
|
||||
public:
|
||||
List() {}
|
||||
List() : head(0), tail(0) {}
|
||||
~List() {}
|
||||
|
||||
~List()
|
||||
void add(T* entry)
|
||||
{
|
||||
AutoMutex am(mutex);
|
||||
while(!head.isEmpty())
|
||||
head.getNext()->del();
|
||||
}
|
||||
ListEntry<T>* tmp = (ListEntry<T>*)entry;
|
||||
tmp->next = NULL;
|
||||
|
||||
void add(const T* part)
|
||||
{
|
||||
ListEntry<T>* entry = new ListEntry<T>(part);
|
||||
if (!head)
|
||||
head = tmp;
|
||||
|
||||
AutoMutex am(mutex);
|
||||
entry->add(&head, head.getNext());
|
||||
}
|
||||
|
||||
void addTail(const T* part)
|
||||
{
|
||||
ListEntry<T>* entry = new ListEntry<T>(part);
|
||||
|
||||
AutoMutex am(mutex);
|
||||
entry->add(head.getPrev(), &head);
|
||||
if (tail)
|
||||
tail->next = tmp;
|
||||
tail = tmp;
|
||||
}
|
||||
|
||||
T* get()
|
||||
{
|
||||
AutoMutex am(mutex);
|
||||
ListEntry<T>* entry = head.getNext();
|
||||
T* retval = (T*)entry->getPart();
|
||||
ListEntry<T>* retval = head;
|
||||
|
||||
if (!head.isEmpty()) {
|
||||
entry->del();
|
||||
delete entry;
|
||||
}
|
||||
return retval;
|
||||
if (head)
|
||||
head = head->next;
|
||||
|
||||
if (!head)
|
||||
tail = NULL;
|
||||
|
||||
return (T*)retval;
|
||||
}
|
||||
|
||||
T* getTail()
|
||||
T* peekHead()
|
||||
{
|
||||
AutoMutex am(mutex);
|
||||
ListEntry<T>* entry = head.getPrev();
|
||||
T* retval = (T*)entry->getPart();
|
||||
|
||||
if (!head.isEmpty()) {
|
||||
entry->del();
|
||||
delete entry;
|
||||
}
|
||||
return retval;
|
||||
return (T*)head;
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
T* peekTail()
|
||||
{
|
||||
AutoMutex am((Mutex&)mutex);
|
||||
return head.isEmpty();
|
||||
return (T*)tail;
|
||||
}
|
||||
|
||||
Iterator<T>* createIterator() const
|
||||
bool isEmpty()
|
||||
{
|
||||
return (head == NULL);
|
||||
}
|
||||
|
||||
Iterator<T>* createIterator()
|
||||
{
|
||||
return new ListIterator<T>(this);
|
||||
}
|
||||
|
@ -86,82 +97,147 @@ protected:
|
|||
List& operator=(const List& l);
|
||||
|
||||
private:
|
||||
template <class TT>
|
||||
class ListEntry {
|
||||
public:
|
||||
ListEntry(const TT* part = 0)
|
||||
: prev(this), next(this), part(part)
|
||||
{
|
||||
}
|
||||
|
||||
void add(ListEntry<TT>* prev_, ListEntry<TT>* next_)
|
||||
{
|
||||
this->next = next_;
|
||||
this->prev = prev_;
|
||||
next_->prev = this;
|
||||
prev_->next = this;
|
||||
}
|
||||
|
||||
void del()
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
next = prev = this;
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return (this->prev == this) && (this->next == this);
|
||||
}
|
||||
|
||||
const TT* getPart() const { return part; }
|
||||
ListEntry<TT>* getPrev() const { return prev; }
|
||||
ListEntry<TT>* getNext() const { return next; }
|
||||
|
||||
private:
|
||||
ListEntry<TT>* prev;
|
||||
ListEntry<TT>* next;
|
||||
const TT* part;
|
||||
};
|
||||
|
||||
ListEntry<T> head;
|
||||
Mutex mutex;
|
||||
|
||||
template <class TT>
|
||||
class ListIterator : public Iterator<TT> {
|
||||
public:
|
||||
ListIterator(const List<TT>* list)
|
||||
: list(list)
|
||||
{
|
||||
// ((ListBase*)list)->mutex.lock();
|
||||
pos = &list->head;
|
||||
}
|
||||
|
||||
~ListIterator()
|
||||
{
|
||||
// ((ListBase*)list)->mutex.unlock();
|
||||
}
|
||||
|
||||
bool hasNext() const
|
||||
{
|
||||
return (pos->getNext() != &list->head);
|
||||
}
|
||||
|
||||
TT* next()
|
||||
{
|
||||
pos = pos->getNext();
|
||||
return (TT*)pos->getPart();
|
||||
}
|
||||
|
||||
protected:
|
||||
ListIterator(const ListIterator& lit);
|
||||
ListIterator& operator=(const ListIterator& lit);
|
||||
|
||||
private:
|
||||
const List<TT>* list;
|
||||
const ListEntry<TT>* pos;
|
||||
};
|
||||
ListEntry<T> *head;
|
||||
ListEntry<T> *tail;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class ListIterator : public Iterator<T> {
|
||||
public:
|
||||
ListIterator(List<T>* list)
|
||||
: list(list)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
virtual ~ListIterator() {}
|
||||
|
||||
virtual bool hasNext()
|
||||
{
|
||||
return (pos == NULL) ? (list->head != NULL) : (pos->next != NULL);
|
||||
}
|
||||
|
||||
virtual T* next()
|
||||
{
|
||||
prev = pos;
|
||||
pos = (pos == NULL) ? list->head : pos->next;
|
||||
return (T*)pos;
|
||||
}
|
||||
|
||||
virtual void remove()
|
||||
{
|
||||
// remove pre-head -> bail out
|
||||
if (pos == NULL)
|
||||
return;
|
||||
|
||||
// remove first
|
||||
if (pos == list->head)
|
||||
list->head = pos->next;
|
||||
|
||||
// remove middle
|
||||
if (prev)
|
||||
prev->next = pos->next;
|
||||
|
||||
// remove last
|
||||
if (pos == list->tail)
|
||||
list->tail = (prev == NULL) ? NULL : prev;
|
||||
|
||||
pos = prev;
|
||||
}
|
||||
|
||||
virtual void reset()
|
||||
{
|
||||
pos = NULL;
|
||||
prev = NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
ListIterator(const ListIterator& li);
|
||||
ListIterator& operator=(const ListIterator& li);
|
||||
|
||||
List<T>* list;
|
||||
|
||||
private:
|
||||
ListEntry<T>* pos;
|
||||
ListEntry<T>* prev;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class ListEntry {
|
||||
friend class List<T>;
|
||||
friend class ListIterator<T>;
|
||||
public:
|
||||
ListEntry() {}
|
||||
~ListEntry() {}
|
||||
|
||||
private:
|
||||
ListEntry* next;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class LockedListIterator;
|
||||
|
||||
|
||||
template <class T>
|
||||
class LockedList : private List<T> {
|
||||
friend class LockedListIterator<T>;
|
||||
public:
|
||||
LockedList() {}
|
||||
~LockedList() {}
|
||||
void add(T* entry)
|
||||
{
|
||||
AutoMutex am(mutex);
|
||||
List<T>::add(entry);
|
||||
}
|
||||
|
||||
T* get()
|
||||
{
|
||||
AutoMutex am(mutex);
|
||||
return List<T>::get();
|
||||
}
|
||||
|
||||
T* peekFirst()
|
||||
{
|
||||
return NULL; // not with lockedlist
|
||||
}
|
||||
|
||||
T* peekLast()
|
||||
{
|
||||
return NULL; // not with lockedlist
|
||||
}
|
||||
|
||||
bool isEmpty()
|
||||
{
|
||||
AutoMutex am(mutex);
|
||||
return List<T>::isEmpty();
|
||||
}
|
||||
|
||||
Iterator<T>* createIterator()
|
||||
{
|
||||
return new LockedListIterator<T>(this);
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex mutex;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class LockedListIterator : public ListIterator<T> {
|
||||
public:
|
||||
LockedListIterator(LockedList<T>* list)
|
||||
: ListIterator<T>(list)
|
||||
{
|
||||
list->mutex.lock();
|
||||
}
|
||||
|
||||
virtual ~LockedListIterator()
|
||||
{
|
||||
((LockedList<T>*)list)->mutex.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_LIST_H_
|
||||
|
|
67
logging.cpp
67
logging.cpp
|
@ -1,3 +1,22 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
@ -7,18 +26,13 @@
|
|||
|
||||
#include "logging.h"
|
||||
|
||||
#define BUFLEN 1024
|
||||
|
||||
|
||||
LogSystem::LogSystem() : output(0), priority(0)
|
||||
LogSystem::LogSystem()
|
||||
: output(0), priority(0)
|
||||
{
|
||||
buffer = new char[BUFLEN];
|
||||
}
|
||||
|
||||
LogSystem::~LogSystem()
|
||||
{
|
||||
delete buffer;
|
||||
|
||||
if (output)
|
||||
delete output;
|
||||
}
|
||||
|
@ -32,14 +46,39 @@ LogSystem* LogSystem::getInstance()
|
|||
void LogSystem::init(int prio, LogOutput* out)
|
||||
{
|
||||
LogSystem* ls = getInstance();
|
||||
if (out) {
|
||||
if (ls->output)
|
||||
delete ls->output;
|
||||
|
||||
if (ls->output)
|
||||
delete ls->output;
|
||||
|
||||
ls->output = out;
|
||||
ls->output = out;
|
||||
}
|
||||
ls->priority = prio;
|
||||
}
|
||||
|
||||
void LogSystem::init(const char* prio, LogOutput* out)
|
||||
{
|
||||
if (!strcasecmp(prio, "DEBUG"))
|
||||
init(LOG_DEBUG, out);
|
||||
|
||||
else if (!strcasecmp(prio, "INFO"))
|
||||
init(LOG_INFO, out);
|
||||
|
||||
else if (!strcasecmp(prio, "NOTICE"))
|
||||
init(LOG_NOTICE, out);
|
||||
|
||||
else if (!strcasecmp(prio, "WARN"))
|
||||
init(LOG_WARN, out);
|
||||
|
||||
else if (!strcasecmp(prio, "ERROR"))
|
||||
init(LOG_ERROR, out);
|
||||
|
||||
else if (!strcasecmp(prio, "CRIT"))
|
||||
init(LOG_CRIT, out);
|
||||
|
||||
else
|
||||
log(LOG_CRIT, "invalid logging priority");
|
||||
}
|
||||
|
||||
void LogSystem::log(int prio, const char* fmt, ...)
|
||||
{
|
||||
LogSystem* ls = getInstance();
|
||||
|
@ -51,13 +90,13 @@ void LogSystem::log(int prio, const char* fmt, ...)
|
|||
int len;
|
||||
|
||||
va_start(az, fmt);
|
||||
len = vsnprintf(ls->buffer, BUFLEN, fmt, az);
|
||||
len = vsnprintf(ls->buffer, sizeof(ls->buffer), fmt, az);
|
||||
va_end(az);
|
||||
|
||||
if (errno) {
|
||||
strncpy(ls->buffer + len, ": ", BUFLEN - len);
|
||||
strncpy(ls->buffer + len, ": ", sizeof(ls->buffer) - len);
|
||||
len += 2;
|
||||
strncpy(ls->buffer + len, strerror(errno), BUFLEN - len);
|
||||
strncpy(ls->buffer + len, strerror(errno), sizeof(ls->buffer) - len);
|
||||
|
||||
errno = 0;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// normal "debug" (config, recv. packets)
|
||||
#define LOG_INFO 4
|
||||
|
||||
// interesting stuff
|
||||
// interesting stuff (unknown packets)
|
||||
#define LOG_NOTICE 3
|
||||
|
||||
// something is not right, but programm is still working (config errors)
|
||||
|
@ -32,6 +32,7 @@ public:
|
|||
class LogSystem {
|
||||
public:
|
||||
static void init(int prio, LogOutput* lo);
|
||||
static void init(const char* prio, LogOutput* lo);
|
||||
static void log(int prio, const char* fmt, ...);
|
||||
|
||||
private:
|
||||
|
@ -41,7 +42,7 @@ private:
|
|||
|
||||
LogOutput *output;
|
||||
int priority;
|
||||
char* buffer;
|
||||
char buffer[8192]; // we need this for (large) packet dumps!
|
||||
};
|
||||
|
||||
class StdErrLog : public LogOutput {
|
||||
|
|
|
@ -0,0 +1,252 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
struct _entry {
|
||||
uint16_t gameid;
|
||||
uint32_t ip;
|
||||
uint16_t port1;
|
||||
uint16_t port2;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
static char hlswheader[] = "\xFF\xFF\xFF\xFFHLSWLANSEARCH";
|
||||
|
||||
static char *id2name[] = {
|
||||
"Unknown", // 0
|
||||
"Halflife",
|
||||
"Quake 1",
|
||||
"Quake 2",
|
||||
"Q3Comp",
|
||||
"Unreal Tournament", // 5
|
||||
"Quake 3 Arena",
|
||||
"Elite Force",
|
||||
"Return to Castle Wolfenstein",
|
||||
"GSProt",
|
||||
"Command & Conquer Renegade", // 10
|
||||
"Medal of Honor: Allied Assault",
|
||||
"Jedi Knight 2",
|
||||
"Soldier of Fortune",
|
||||
"Unreal Tournament 2003",
|
||||
"America's Army: Operations", // 15
|
||||
"Battlefield 1942",
|
||||
"Alien vs. Predator 2",
|
||||
"Rune",
|
||||
"Project IGI2: Covert Strike",
|
||||
"Never Winter Nights", // 20
|
||||
"Medal of Honor: Allied Assault Spearhead",
|
||||
"Operation Flashpoint",
|
||||
"Operation Flashpoint Resistance",
|
||||
"Devastation",
|
||||
"Wolfenstein - Enemy Territory", //25
|
||||
"Elite Force 2",
|
||||
"Jedi Knight 3",
|
||||
"Medal of Honor: Allied Assault Breakthrough",
|
||||
"Tribes 2",
|
||||
"Halo", // 30
|
||||
"Call of Duty",
|
||||
"Savage: The Battle for Newerth",
|
||||
"Unreal Tournament 2004",
|
||||
"HLSteam",
|
||||
"Battlefield Vietnam", // 35
|
||||
"GS2Prot",
|
||||
"Pain Killer",
|
||||
"Doom 3",
|
||||
"OGPProt",
|
||||
"Halflife 2", // 40
|
||||
"Tribes Vengeance",
|
||||
"Call of Duty: United Offensive",
|
||||
"Starwars: Battlefront (?)",
|
||||
"SWAT 4",
|
||||
"Battlefield 2", // 45
|
||||
"?",
|
||||
"Quake 4 (?)",
|
||||
"Call of Duty 2"
|
||||
};
|
||||
|
||||
static int sock, verbose = 0;
|
||||
|
||||
static void parse_pkt(struct sockaddr_in *src, void *pkt, unsigned int size)
|
||||
{
|
||||
struct _entry *server;
|
||||
struct in_addr tmp;
|
||||
|
||||
if (size < sizeof(hlswheader) || strncmp(pkt, hlswheader, sizeof(hlswheader))) {
|
||||
printf("received INVALID packet from: %15s:%-5d size=%d\n",
|
||||
inet_ntoa(src->sin_addr), ntohs(src->sin_port), size);
|
||||
|
||||
} else {
|
||||
printf("received hlsw packet from: %15s:%-5d size=%d count=%d\n",
|
||||
inet_ntoa(src->sin_addr), ntohs(src->sin_port), size,
|
||||
((size > sizeof(hlswheader)) ? (size - sizeof(hlswheader)) / sizeof(struct _entry) : 0));
|
||||
|
||||
if (verbose) {
|
||||
server = pkt + sizeof(hlswheader);
|
||||
while ((void *)server < pkt + size) {
|
||||
tmp.s_addr = server->ip;
|
||||
printf(" ip=%15s port1=%5d port2=%5d gameid=%2d (%s)\n",
|
||||
inet_ntoa(tmp), server->port1, server->port2,
|
||||
server->gameid, id2name[server->gameid]);
|
||||
server++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int scan_init()
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i))) {
|
||||
perror("setsockopt()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int scan_transmit(struct sockaddr_in *dst)
|
||||
{
|
||||
if (sendto(sock, hlswheader, sizeof(hlswheader), 0, (struct sockaddr *)dst, sizeof(struct sockaddr_in)) < 0) {
|
||||
perror("sendto()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int scan_receive()
|
||||
{
|
||||
struct sockaddr_in src;
|
||||
struct timeval tv;
|
||||
fd_set fdsel;
|
||||
unsigned int i = 1, recvsize;
|
||||
void *pkt;
|
||||
|
||||
FD_ZERO(&fdsel);
|
||||
FD_SET(sock, &fdsel);
|
||||
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
/* timeout */
|
||||
while (tv.tv_sec > 0 || tv.tv_usec > 0) {
|
||||
|
||||
if (select(FD_SETSIZE, &fdsel, NULL, NULL, &tv) < 0) {
|
||||
perror("select()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get packetsize */
|
||||
if (ioctl(sock, FIONREAD, &recvsize) == -1) {
|
||||
perror("ioctl()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (recvsize > 0) {
|
||||
if (!(pkt = malloc(recvsize))) {
|
||||
perror("malloc()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
i = sizeof(struct sockaddr_in);
|
||||
recvsize = recvfrom(sock, pkt, recvsize, 0, (struct sockaddr *)&src, &i);
|
||||
|
||||
parse_pkt(&src, pkt, recvsize);
|
||||
|
||||
free(pkt);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct option opts[] = {
|
||||
{"destination", 1, 0, 'd'},
|
||||
{"intervall", 1, 0, 'i'},
|
||||
{"verbose", 0, 0, 'v'},
|
||||
{"help", 0, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sockaddr_in dst;
|
||||
int arg = 0, code = 0;
|
||||
int freq = -1;
|
||||
|
||||
dst.sin_family = AF_INET;
|
||||
dst.sin_port = htons(7140);
|
||||
inet_aton("255.255.255.255", &dst.sin_addr);
|
||||
|
||||
while (code != -1) {
|
||||
code = getopt_long(argc, argv, "d:i:vh", opts, &arg);
|
||||
|
||||
switch (code) {
|
||||
case 'd': /* destination */
|
||||
if (inet_pton(dst.sin_family, optarg, &dst.sin_addr) <= 0) {
|
||||
fprintf(stderr, "invalid destination: %s\n", optarg);
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'i': /* intervall */
|
||||
freq = atoi(optarg);
|
||||
if (freq < 1) {
|
||||
fprintf(stderr, "invalid interval: %s\n", optarg);
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v': /* verbose */
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
case 'h': /* help */
|
||||
printf("Usage: masterquery [options]\n"
|
||||
"Options: \n"
|
||||
" --destination -d scan destination <ip>\n"
|
||||
" --intervall -i scan intervall in seconds\n"
|
||||
" --verbose -v verbose: show packet content\n"
|
||||
" --help -h this help\n"
|
||||
"\n");
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
case '?': /* error */
|
||||
exit(-1);
|
||||
break;
|
||||
|
||||
default: /* unknown / all options parsed */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (scan_init())
|
||||
exit(-1);
|
||||
|
||||
do {
|
||||
if (scan_transmit(&dst))
|
||||
exit(-1);
|
||||
|
||||
if (scan_receive())
|
||||
exit(-1);
|
||||
|
||||
} while (freq >= 1 && !sleep(freq -1));
|
||||
|
||||
close(sock);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_d3engine.h"
|
||||
#include "modhelper.h"
|
||||
|
||||
static struct game_ports port_arr[] = {
|
||||
{ 27666, 27673, ID_D3 }, // Doom 3
|
||||
{ 28004, 28008, ID_Q4 }, // Quake 4
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static const char scanmsg[] = "\xff\xffgetInfo";
|
||||
static const char replyhead[] = "\xff\xffinfoResponse";
|
||||
|
||||
void ModD3Engine::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, port_arr, scanmsg, strlen(scanmsg));
|
||||
}
|
||||
|
||||
int ModD3Engine::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
int gameid;
|
||||
|
||||
gameid = ModHelper::checkPorts(pkt, port_arr);
|
||||
if (!gameid)
|
||||
return PARSE_REJECT;
|
||||
|
||||
if (!pkt->compare(0, replyhead, strlen(replyhead)))
|
||||
return PARSE_REJECT;
|
||||
|
||||
glist->addGame(gameid, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MODD3ENGINE_H_
|
||||
#define _MODD3ENGINE_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class ModD3Engine : public Module {
|
||||
public:
|
||||
ModD3Engine() {}
|
||||
~ModD3Engine() {}
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* slist);
|
||||
|
||||
const char* getName() { return "Doom3 protocol"; }
|
||||
};
|
||||
|
||||
#endif // _MODD3ENGINE_H_
|
|
@ -1,35 +0,0 @@
|
|||
#ifndef _MODEXAMPLE_H_
|
||||
#define _MODEXAMPLE_H_
|
||||
|
||||
#include "modulelist.h"
|
||||
#include "logging.h"
|
||||
|
||||
class ModExample : public Module {
|
||||
public:
|
||||
ModExample(Config& conf)
|
||||
{
|
||||
}
|
||||
|
||||
~ModExample()
|
||||
{
|
||||
}
|
||||
|
||||
void scan(MultiSock* msock)
|
||||
{
|
||||
LogSystem::log(LOG_DEBUG, "ModExample::scan()");
|
||||
}
|
||||
|
||||
int parse(NetPkt* pkt, GameList* slist)
|
||||
{
|
||||
LogSystem::log(LOG_DEBUG, "ModExample::parse()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* getName() {
|
||||
return "Example Module";
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif // _MODEXAMPLE_H_
|
|
@ -0,0 +1,311 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_gamespy1.h"
|
||||
#include "modhelper.h"
|
||||
#include "logging.h"
|
||||
|
||||
#define MODGS1_GC_TIMEOUT 5
|
||||
|
||||
static struct game_ports port_arr[] = {
|
||||
{ 7777, 7788, ID_UT }, // ut, ut2k3, rune, ut2k4, aao, POSTAL2
|
||||
{ 22000, 22010, ID_BF1942 }, // bf1942(16)
|
||||
{ 23000, 23010, ID_BFV }, // bfv(35)
|
||||
{ 26001, 26011, ID_IGI2 }, // igi2(19)
|
||||
{ 27888, 27888, ID_AVP2 }, // avp2(17), FEAR
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static const char scanmsg[] = "\\status\\";
|
||||
static const char search_queryid[] = "\\queryid\\";
|
||||
static const char search_final[] = "\\final\\";
|
||||
|
||||
static const char search_hostport[] = "\\hostport\\";
|
||||
static const char search_gamename[] = "\\gamename\\";
|
||||
static const char search_gsgamename[] = "\\gsgamename\\";
|
||||
static const char search_gameid[] = "\\game_id\\";
|
||||
|
||||
static const char reply_ut[] = "ut\\";
|
||||
static const char reply_ut2k3[] = "ut2\\";
|
||||
static const char reply_ut2k4[] = "ut2004\\";
|
||||
static const char reply_bf1942[] = "bfield1942\\";
|
||||
static const char reply_bfv1[] = "bfvietnam\\";
|
||||
static const char reply_bfv2[] = "BFVIETNAM\\";
|
||||
static const char reply_poe[] = "poe\\";
|
||||
static const char reply_opk[] = "opk\\";
|
||||
static const char reply_avp2[] = "avp2\\";
|
||||
static const char reply_igi2[] = "projectigi2r\\";
|
||||
static const char reply_aao[] = "armygame\\";
|
||||
static const char reply_rune[] = "rune\\";
|
||||
static const char reply_postal2[] = "postal2\\";
|
||||
static const char reply_fear[] = "fear\\";
|
||||
|
||||
ModGameSpy1::ModGameSpy1()
|
||||
{
|
||||
TimerService::registerTimer(new Timer(new GcEvent(*this), MODGS1_GC_TIMEOUT));
|
||||
}
|
||||
|
||||
ModGameSpy1::~ModGameSpy1()
|
||||
{
|
||||
while (!list.isEmpty())
|
||||
delete list.get();
|
||||
}
|
||||
|
||||
void ModGameSpy1::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, port_arr, scanmsg, strlen(scanmsg));
|
||||
}
|
||||
|
||||
int ModGameSpy1::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
NetPkt* pkt2;
|
||||
int gameid, pos, offset, queryid, subid, retval;
|
||||
bool final;
|
||||
|
||||
gameid = ModHelper::checkPorts(pkt, port_arr);
|
||||
if (!gameid)
|
||||
return PARSE_REJECT;
|
||||
|
||||
/* eat ut connection attemps */
|
||||
if (gameid == 5 && pkt->getSize() <= 6)
|
||||
return PARSE_ACCEPT_QUIRK;
|
||||
|
||||
offset = pkt->find(0, search_queryid, strlen(search_queryid));
|
||||
if (offset == -1)
|
||||
return PARSE_REJECT;
|
||||
|
||||
pos = offset + strlen(search_queryid);
|
||||
offset = pkt->parse_int(pos, &queryid);
|
||||
if (offset == 0)
|
||||
return PARSE_REJECT;
|
||||
|
||||
pos += offset +1;
|
||||
offset = pkt->parse_int(pos, &subid);
|
||||
if (offset == 0)
|
||||
return PARSE_REJECT;
|
||||
|
||||
offset = pkt->find(0, search_final, strlen(search_final));
|
||||
final = (offset != -1);
|
||||
|
||||
char buf[64];
|
||||
pkt->show(buf, sizeof(buf));
|
||||
|
||||
/* single final packet -> shortcut */
|
||||
if (final && (subid == 1)) {
|
||||
pkt2 = pkt;
|
||||
|
||||
/* non-final multi-part */
|
||||
} else if (!final) {
|
||||
LogSystem::log(LOG_DEBUG, "non final %s (%d/%d)", buf, queryid, subid);
|
||||
list.add(new MultiPart(pkt, queryid, subid));
|
||||
return PARSE_ACCEPT_FREED; // parser must not free pkt
|
||||
|
||||
/* final multipart */
|
||||
} else {
|
||||
LogSystem::log(LOG_DEBUG, "multi final %s (%d/%d)", buf, queryid, subid);
|
||||
pkt2 = merge(pkt, queryid, subid);
|
||||
if (pkt2 == NULL) {
|
||||
LogSystem::log(LOG_NOTICE, "ModGameSpy1: failed to merge");
|
||||
return PARSE_ACCEPT; // let parser free pkt
|
||||
}
|
||||
}
|
||||
|
||||
retval = parse_real(pkt2, glist, gameid);
|
||||
|
||||
if (pkt2 != pkt)
|
||||
delete pkt2; // free merged packet
|
||||
|
||||
return retval; // ACCPET/REJECT -> let parser free pkt
|
||||
}
|
||||
|
||||
ModGameSpy1::MultiPart::MultiPart(NetPkt* pkt, int queryid, int subid)
|
||||
: pkt(pkt), queryid(queryid), subid(subid)
|
||||
{
|
||||
timeout = time(NULL) + MODGS1_GC_TIMEOUT;
|
||||
}
|
||||
|
||||
ModGameSpy1::MultiPart::~MultiPart()
|
||||
{
|
||||
delete pkt;
|
||||
}
|
||||
|
||||
NetPkt* ModGameSpy1::merge(NetPkt* pkt, int queryid, int subid)
|
||||
{
|
||||
Iterator<MultiPart>* it = list.createIterator();
|
||||
|
||||
NetPkt* tmppkt = new NetPkt(NULL, 0);
|
||||
tmppkt->setAddress(pkt->getAddress());
|
||||
|
||||
bool found;
|
||||
int searchid = 1;
|
||||
do {
|
||||
found = false;
|
||||
while (it->hasNext()) {
|
||||
MultiPart* mp = it->next();
|
||||
if (!pkt->sameAddress(mp->pkt))
|
||||
continue;
|
||||
|
||||
if (queryid != mp->queryid)
|
||||
continue;
|
||||
|
||||
it->remove();
|
||||
found = true;
|
||||
|
||||
if (searchid == mp->subid) {
|
||||
tmppkt->merge(mp->pkt);
|
||||
delete mp;
|
||||
searchid++;
|
||||
}
|
||||
}
|
||||
|
||||
it->reset();
|
||||
} while (found && (searchid < subid));
|
||||
|
||||
delete it;
|
||||
|
||||
tmppkt->merge(pkt);
|
||||
|
||||
if (!found) {
|
||||
delete tmppkt;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tmppkt;
|
||||
}
|
||||
|
||||
void ModGameSpy1::gc()
|
||||
{
|
||||
Iterator<MultiPart>* it = list.createIterator();
|
||||
long now = time(NULL);
|
||||
char buf[64];
|
||||
|
||||
while (it->hasNext()) {
|
||||
MultiPart* mp = it->next();
|
||||
if (mp->timeout <= now) {
|
||||
mp->pkt->show(buf, sizeof(buf));
|
||||
LogSystem::log(LOG_NOTICE, "ModGameSpy1 gc removed: %s (%d/%d)",
|
||||
buf, mp->queryid, mp->subid);
|
||||
it->remove();
|
||||
delete mp;
|
||||
}
|
||||
}
|
||||
delete it;
|
||||
}
|
||||
|
||||
int ModGameSpy1::parse_real(NetPkt* pkt, GameList* glist, int gameid)
|
||||
{
|
||||
int port, offset, pos1, pos2;
|
||||
|
||||
pos1 = pkt->find(0, search_gamename, strlen(search_gamename));
|
||||
pos1 += strlen(search_gamename);
|
||||
|
||||
switch (gameid) {
|
||||
case ID_UT:
|
||||
if (pkt->compare(pos1, reply_ut, strlen(reply_ut)))
|
||||
gameid = ID_UT;
|
||||
|
||||
else if (pkt->compare(pos1, reply_ut2k3, strlen(reply_ut2k4)))
|
||||
gameid = ID_UT2K3;
|
||||
|
||||
else if (pkt->compare(pos1, reply_ut2k4, strlen(reply_ut2k4)))
|
||||
gameid = ID_UT2K4;
|
||||
|
||||
else if (pkt->compare(pos1, reply_aao, strlen(reply_aao)))
|
||||
gameid = ID_AAO;
|
||||
|
||||
else if (pkt->compare(pos1, reply_postal2, strlen(reply_postal2)))
|
||||
return PARSE_ACCEPT_FAKE;
|
||||
|
||||
else
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
|
||||
case ID_BF1942:
|
||||
case ID_BFV:
|
||||
pos2 = pkt->find(0, search_gameid, strlen(search_gameid));
|
||||
pos2 += strlen(search_gameid);
|
||||
|
||||
if (pkt->compare(pos1, reply_bf1942, strlen(reply_bf1942)))
|
||||
gameid = ID_BF1942;
|
||||
|
||||
else if (pkt->compare(pos2, reply_bfv1, strlen(reply_bfv1)))
|
||||
gameid = ID_BFV;
|
||||
|
||||
else if (pkt->compare(pos2, reply_bfv2, strlen(reply_bfv2)))
|
||||
gameid = ID_BFV;
|
||||
|
||||
else if (pkt->compare(pos2, reply_poe, strlen(reply_poe)))
|
||||
gameid = ID_BFV;
|
||||
|
||||
else if (pkt->compare(pos2, reply_opk, strlen(reply_opk)))
|
||||
gameid = ID_BFV;
|
||||
else
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
|
||||
case ID_AVP2:
|
||||
pos2 = pkt->find(0, search_gsgamename, strlen(search_gsgamename));
|
||||
pos2 += strlen(search_gsgamename);
|
||||
|
||||
if (pkt->compare(pos1, reply_avp2, strlen(reply_avp2)))
|
||||
gameid = ID_AVP2;
|
||||
|
||||
else if (pkt->compare(pos2, reply_fear, strlen(reply_fear)))
|
||||
return PARSE_ACCEPT_FAKE;
|
||||
|
||||
else
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
|
||||
case ID_RUNE:
|
||||
if (pkt->compare(pos1, reply_rune, strlen(reply_rune)))
|
||||
gameid = ID_RUNE;
|
||||
else
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
|
||||
case ID_IGI2:
|
||||
if (pkt->compare(pos1, reply_igi2, strlen(reply_igi2)))
|
||||
gameid = ID_IGI2;
|
||||
else
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
|
||||
default:
|
||||
return PARSE_REJECT;
|
||||
}
|
||||
|
||||
/* hostport angabe suchen */
|
||||
offset = pkt->find(0, search_hostport, strlen(search_hostport));
|
||||
if (offset != -1)
|
||||
pkt->parse_int(offset + strlen(search_hostport), &port);
|
||||
|
||||
/*
|
||||
* wenn ein hostport angegeben wurde, und das nicht der src port ist
|
||||
* beide ports in die serverliste uebernehmen
|
||||
*/
|
||||
if ((offset != -1) && (port != pkt->getPort())) {
|
||||
glist->addGame(gameid, pkt, port);
|
||||
|
||||
} else {
|
||||
glist->addGame(gameid, pkt);
|
||||
}
|
||||
return PARSE_ACCEPT;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef _MODGAMESPY1_H_
|
||||
#define _MODGAMESPY1_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
#include "list.h"
|
||||
#include "timerservice.h"
|
||||
|
||||
class ModGameSpy1 : public Module {
|
||||
public:
|
||||
ModGameSpy1();
|
||||
~ModGameSpy1();
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* glist);
|
||||
|
||||
const char* getName() { return "GameSpy 1 protocol"; }
|
||||
|
||||
void gc();
|
||||
|
||||
private:
|
||||
class MultiPart : private ListEntry<MultiPart> {
|
||||
public:
|
||||
MultiPart(NetPkt* pkt, int queryid, int subid);
|
||||
~MultiPart();
|
||||
|
||||
NetPkt* pkt;
|
||||
int queryid;
|
||||
int subid;
|
||||
|
||||
long timeout;
|
||||
};
|
||||
|
||||
class GcEvent : public Event {
|
||||
public:
|
||||
GcEvent(ModGameSpy1& mgs1) : mgs1(mgs1) {}
|
||||
~GcEvent() {}
|
||||
void execute() { mgs1.gc(); }
|
||||
|
||||
private:
|
||||
ModGameSpy1& mgs1;
|
||||
};
|
||||
|
||||
NetPkt* merge(NetPkt* pkt, int queryid, int subid);
|
||||
int parse_real(NetPkt* pkt, GameList* glist, int gameid);
|
||||
|
||||
LockedList<MultiPart> list;
|
||||
};
|
||||
|
||||
#endif // _MODGAMESPY1_H_
|
|
@ -0,0 +1,107 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_gamespy2.h"
|
||||
#include "modhelper.h"
|
||||
#include "logging.h"
|
||||
|
||||
static struct game_ports port_arr[] = {
|
||||
{ 2302, 2302, ID_HALO },
|
||||
{ 3455, 3455, ID_PK },
|
||||
{ 10481, 10482, ID_SWAT4 },
|
||||
{ 29900, 29910, ID_BF2 },
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
static const char scanmsg[] = { 0xFE, 0xFD, 0x00, 0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0x00, 0x00 };
|
||||
static const char replyhead[] = { 0x00, 0xDE, 0xAD, 0xBE, 0xEF };
|
||||
|
||||
static const char search_hostport[] = "hostport";
|
||||
static const char search_gamename[] = "gamename";
|
||||
|
||||
static const char reply_bf2[] = "battlefield2";
|
||||
|
||||
void ModGameSpy2::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, port_arr, scanmsg, sizeof(scanmsg));
|
||||
}
|
||||
|
||||
int ModGameSpy2::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
int gameid, pos1, pos2, port;
|
||||
|
||||
gameid = ModHelper::checkPorts(pkt, port_arr);
|
||||
if (!gameid)
|
||||
return PARSE_REJECT;
|
||||
|
||||
if (!pkt->compare(0, replyhead, sizeof(replyhead)))
|
||||
return PARSE_REJECT;
|
||||
|
||||
pos1 = pkt->find(0, search_gamename, strlen(search_gamename));
|
||||
pos1 += strlen(search_gamename) +1;
|
||||
|
||||
/* hostport angabe suchen */
|
||||
pos2 = pkt->find(0, search_hostport, strlen(search_hostport));
|
||||
if (pos2 != -1) {
|
||||
pos2 += strlen(search_hostport) +1;
|
||||
pkt->parse_int(pos2, &port);
|
||||
}
|
||||
|
||||
switch (gameid) {
|
||||
case ID_HALO:
|
||||
case ID_PK:
|
||||
break;
|
||||
|
||||
case ID_SWAT4:
|
||||
if (pos2 == -1)
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
|
||||
case ID_BF2:/* battlefield 2 */
|
||||
// TODO: pos2 check noetig?
|
||||
if (pos2 == -1) {
|
||||
LogSystem::log(LOG_DEBUG, "no hostport found");
|
||||
return PARSE_REJECT;
|
||||
}
|
||||
|
||||
if (pkt->find(pos1, reply_bf2, strlen(reply_bf2)) == -1) {
|
||||
LogSystem::log(LOG_DEBUG, "no gamename found");
|
||||
return PARSE_REJECT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return PARSE_REJECT;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* wenn ein hostport angegeben wurde, und das nicht der src port ist
|
||||
* beide ports in die serverliste uebernehmen
|
||||
*/
|
||||
if ((pos2 != -1) && (port != pkt->getPort())) {
|
||||
glist->addGame(gameid, pkt, port);
|
||||
|
||||
} else {
|
||||
glist->addGame(gameid, pkt);
|
||||
}
|
||||
|
||||
return PARSE_ACCEPT;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MODGAMESPY2_H_
|
||||
#define _MODGAMESPY2_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class ModGameSpy2 : public Module {
|
||||
public:
|
||||
ModGameSpy2() {}
|
||||
~ModGameSpy2() {}
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* glist);
|
||||
|
||||
const char* getName() { return "GameSpy 2 protocol"; }
|
||||
};
|
||||
|
||||
#endif // _MODGAMESPY1_H_
|
|
@ -0,0 +1,90 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_halflife.h"
|
||||
#include "modhelper.h"
|
||||
|
||||
static struct game_ports port_arr[] = {
|
||||
{ 27015, 27024, ID_HL },
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static const char scanmsg1[] = "\xff\xff\xff\xff""details";
|
||||
static const char scanmsg2[] = "\xff\xff\xff\xff\x54";
|
||||
static const char scanmsg3[] = "\xff\xff\xff\xff""TSource Engine Query";
|
||||
|
||||
static const char reply1[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x49, 0x07 }; // I.
|
||||
static const char reply2[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x6D, 0x00 }; // m
|
||||
|
||||
void ModHalfLife::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, port_arr, scanmsg1, strlen(scanmsg1));
|
||||
ModHelper::send(msock, port_arr, scanmsg2, strlen(scanmsg2));
|
||||
ModHelper::send(msock, port_arr, scanmsg3, strlen(scanmsg3));
|
||||
}
|
||||
|
||||
int ModHalfLife::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
struct in_addr tmp;
|
||||
int port, count, pos;
|
||||
|
||||
if (ModHelper::checkPorts(pkt, port_arr) == 0)
|
||||
return PARSE_REJECT;
|
||||
|
||||
// eat weird connection attempts
|
||||
if (pkt->getSize() <= 4)
|
||||
return PARSE_ACCEPT_QUIRK;
|
||||
|
||||
/* Halflife2 answer */
|
||||
if (pkt->compare(0, reply1, sizeof(reply1))) {
|
||||
glist->addGame(ID_HL2, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
||||
|
||||
/* Halflife1 short answer */
|
||||
if (pkt->compare(0, reply2, sizeof(reply2))) {
|
||||
glist->addGame(ID_HL, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
||||
|
||||
/* Halflife1 answer (with IP:port) */
|
||||
if (!pkt->compare(0, reply2, sizeof(reply2) -1))
|
||||
return PARSE_REJECT;
|
||||
|
||||
/* try to parse server IP */
|
||||
pos = 5;
|
||||
if ((count = pkt->parse_ip(pos, &tmp)) < 7)
|
||||
return PARSE_REJECT;
|
||||
|
||||
/* parse server port */
|
||||
pos += count +1;
|
||||
if ((count = pkt->parse_int(pos, &port)) == 0)
|
||||
return PARSE_REJECT;
|
||||
|
||||
// IP is 0.0.0.0 or 127.0.0.1 -> do not use IP info
|
||||
if (tmp.s_addr == 0x00000000 || tmp.s_addr == 0x0100007F) {
|
||||
glist->addGame(ID_HL, pkt);
|
||||
|
||||
} else {
|
||||
glist->addGame(ID_HL, &tmp, port);
|
||||
}
|
||||
|
||||
return PARSE_ACCEPT;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MODHALFLIFE_H_
|
||||
#define _MODHALFLIFE_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class ModHalfLife : public Module {
|
||||
public:
|
||||
ModHalfLife() {}
|
||||
~ModHalfLife() {}
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* glist);
|
||||
|
||||
const char* getName() { return "Half-Life protocol"; }
|
||||
};
|
||||
|
||||
#endif // _MODHALFLIFE_H_
|
|
@ -0,0 +1,105 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_q3engine.h"
|
||||
#include "modhelper.h"
|
||||
|
||||
static struct game_ports port_arr[] = {
|
||||
{ 27960, 27969, ID_Q3A }, // q3(6), ef(7), et25), rtcw(8)
|
||||
{ 28070, 28070, ID_JK2 }, // jk2(12)
|
||||
{ 28960, 28963, ID_COD }, // cod(31), cod:uo(42), cod2(48)
|
||||
{ 29070, 29070, ID_JK3 }, // jk3(27)
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static const char scanmsg[] = "\xff\xff\xff\xffgetStatus";
|
||||
static const char replyhead[] = "\xff\xff\xff\xffstatusResponse";
|
||||
|
||||
static const char search_version[] = "\\version\\";
|
||||
static const char search_gamename[] = "\\gamename\\";
|
||||
|
||||
static const char reply_q3[] = "Q3 ";
|
||||
static const char reply_ef[] = "ST:V HM ";
|
||||
static const char reply_rtcw[] = "Wolf ";
|
||||
static const char reply_et[] = "ET";
|
||||
static const char reply_jk2[] = "JK2MP";
|
||||
static const char reply_jk3[] = "JAmp";
|
||||
|
||||
static const char reply_cod[] = "Call of Duty\\";
|
||||
static const char reply_coduo[] = "CoD:United Offensive\\";
|
||||
static const char reply_cod2[] = "Call of Duty 2\\";
|
||||
|
||||
void ModQ3Engine::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, port_arr, scanmsg, strlen(scanmsg));
|
||||
}
|
||||
|
||||
int ModQ3Engine::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
int gameid = 0, pos1, pos2;
|
||||
|
||||
gameid = ModHelper::checkPorts(pkt, port_arr);
|
||||
if (!gameid)
|
||||
return PARSE_REJECT;
|
||||
|
||||
if (!pkt->compare(0, replyhead, strlen(replyhead)))
|
||||
return PARSE_REJECT;
|
||||
|
||||
pos1 = pkt->find(0, search_version, strlen(search_version));
|
||||
if (pos1 != -1) {
|
||||
pos1 += strlen(search_version);
|
||||
if (pkt->compare(pos1, reply_q3, strlen(reply_q3)))
|
||||
gameid = ID_Q3A;
|
||||
|
||||
else if (pkt->compare(pos1, reply_ef, strlen(reply_ef)))
|
||||
gameid = ID_EF;
|
||||
|
||||
else if (pkt->compare(pos1, reply_rtcw, strlen(reply_rtcw)))
|
||||
gameid = ID_RTCW;
|
||||
|
||||
else if (pkt->compare(pos1, reply_et, strlen(reply_et)))
|
||||
gameid = ID_ET;
|
||||
|
||||
else if (pkt->compare(pos1, reply_jk2, strlen(reply_jk2)))
|
||||
gameid = ID_JK2;
|
||||
|
||||
else if (pkt->compare(pos1, reply_jk3, strlen(reply_jk3)))
|
||||
gameid = ID_JK3;
|
||||
}
|
||||
|
||||
pos2 = pkt->find(0, search_gamename, strlen(search_gamename));
|
||||
if (gameid == 0 && pos2 != -1) {
|
||||
pos2 += strlen(search_gamename);
|
||||
if (pkt->compare(pos2, reply_cod, strlen(reply_cod)))
|
||||
gameid = ID_COD;
|
||||
|
||||
else if (pkt->compare(pos2, reply_coduo, strlen(reply_coduo)))
|
||||
gameid = ID_COD_UO;
|
||||
|
||||
else if (pkt->compare(pos2, reply_cod2, strlen(reply_cod2)))
|
||||
gameid = ID_COD2;
|
||||
}
|
||||
|
||||
if (gameid == 0)
|
||||
return PARSE_REJECT;
|
||||
|
||||
glist->addGame(gameid, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MODQ3ENGINE_H_
|
||||
#define _MODQ3ENGINE_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class ModQ3Engine : public Module {
|
||||
public:
|
||||
ModQ3Engine() {}
|
||||
~ModQ3Engine() {}
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* glist);
|
||||
|
||||
const char* getName() { return "Quake3 protocol"; }
|
||||
};
|
||||
|
||||
#endif // _MODQ3ENGINE_H_
|
|
@ -0,0 +1,45 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_quake2.h"
|
||||
#include "modhelper.h"
|
||||
|
||||
#define QUAKE2_PORT 27910
|
||||
|
||||
// scan for latest protocol version
|
||||
static const char scanmsg[] = "\xff\xff\xff\xffinfo 34";
|
||||
static const char replyhead[] = "\xff\xff\xff\xffinfo";
|
||||
|
||||
void ModQuake2::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, QUAKE2_PORT, scanmsg, strlen(scanmsg));
|
||||
}
|
||||
|
||||
int ModQuake2::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
if (pkt->getPort() != QUAKE2_PORT)
|
||||
return PARSE_REJECT;
|
||||
|
||||
if (!pkt->compare(0, replyhead, strlen(replyhead)))
|
||||
return PARSE_REJECT;
|
||||
|
||||
glist->addGame(ID_Q2, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MODQUAKE2_H_
|
||||
#define _MODQUAKE2_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class ModQuake2 : public Module {
|
||||
public:
|
||||
ModQuake2() {}
|
||||
~ModQuake2() {}
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* slist);
|
||||
|
||||
const char* getName() { return "Quake2 protocol"; }
|
||||
};
|
||||
|
||||
#endif // _MODQUAKE2_H_
|
|
@ -0,0 +1,58 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "mod_ut.h"
|
||||
#include "modhelper.h"
|
||||
|
||||
static struct game_ports port_arr[] = {
|
||||
{ 7777, 7788, 0 },
|
||||
{ 10777, 10777, 0 },
|
||||
{ 0,0,0 }
|
||||
};
|
||||
|
||||
static const char scanmsg_ut2k3[] = { 0x79, 0x00, 0x00, 0x00, 0x00 };
|
||||
static const char scanmsg_ut2k4[] = { 0x80, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
void ModUT::scan(MultiSock* msock)
|
||||
{
|
||||
ModHelper::send(msock, port_arr, scanmsg_ut2k3, sizeof(scanmsg_ut2k3));
|
||||
ModHelper::send(msock, port_arr, scanmsg_ut2k4, sizeof(scanmsg_ut2k4));
|
||||
}
|
||||
|
||||
int ModUT::parse(NetPkt* pkt, GameList* glist)
|
||||
{
|
||||
/*
|
||||
int gameid;
|
||||
gameid = ModHelper::checkPorts(pkt, port_arr);
|
||||
if (!gameid)
|
||||
return PARSE_REJECT;
|
||||
*/
|
||||
if (pkt->compare(0, scanmsg_ut2k3, sizeof(scanmsg_ut2k3))) {
|
||||
glist->addGame(ID_UT2K3, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
||||
|
||||
if (pkt->compare(0, scanmsg_ut2k4, sizeof(scanmsg_ut2k4))) {
|
||||
glist->addGame(ID_UT2K4, pkt);
|
||||
return PARSE_ACCEPT;
|
||||
}
|
||||
|
||||
return PARSE_REJECT;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _MODUT_H_
|
||||
#define _MODUT_H_
|
||||
|
||||
#include "module.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
class ModUT : public Module {
|
||||
public:
|
||||
ModUT() {}
|
||||
~ModUT() {}
|
||||
|
||||
void scan(MultiSock* msock);
|
||||
int parse(NetPkt* pkt, GameList* slist);
|
||||
|
||||
const char* getName() { return "UT protocol (native)"; }
|
||||
};
|
||||
|
||||
#endif // _MODUT_H_
|
|
@ -0,0 +1,69 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "modhelper.h"
|
||||
|
||||
void ModHelper::send(MultiSock* msock, int port, const char* data, int size)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = 0xFFFFFFFF;
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
NetPkt* pkt = new NetPkt(data, size);
|
||||
pkt->setAddress(&addr);
|
||||
msock->sendto(pkt);
|
||||
|
||||
delete pkt;
|
||||
}
|
||||
|
||||
void ModHelper::send(MultiSock* msock, struct game_ports* arr, const char* data, int size)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = 0xFFFFFFFF;
|
||||
|
||||
NetPkt* pkt = new NetPkt(data, size);
|
||||
|
||||
while (arr && arr->portlo && arr->porthi) {
|
||||
int port;
|
||||
for (port = arr->portlo; port <= arr->porthi; port++) {
|
||||
addr.sin_port = htons(port);
|
||||
pkt->setAddress(&addr);
|
||||
msock->sendto(pkt);
|
||||
}
|
||||
arr++;
|
||||
}
|
||||
|
||||
delete pkt;
|
||||
}
|
||||
|
||||
int ModHelper::checkPorts(NetPkt* pkt, struct game_ports* arr)
|
||||
{
|
||||
int myport = ntohs(pkt->getAddress()->sin_port);
|
||||
while (arr && arr->portlo) {
|
||||
int port;
|
||||
for (port = arr->portlo; port <= arr->porthi; port++)
|
||||
if (port == myport)
|
||||
return arr->gameid;
|
||||
|
||||
arr++;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef _MODHELPER_H_
|
||||
#define _MODHELPER_H_
|
||||
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
|
||||
struct game_ports {
|
||||
int portlo;
|
||||
int porthi;
|
||||
int gameid;
|
||||
};
|
||||
|
||||
class ModHelper {
|
||||
public:
|
||||
static void send(MultiSock* msock, int port, const char* data, int size);
|
||||
static void send(MultiSock* msock, struct game_ports* arr, const char* data, int size);
|
||||
|
||||
static int checkPorts(NetPkt* pkt, struct game_ports* arr);
|
||||
|
||||
protected:
|
||||
ModHelper() {};
|
||||
ModHelper(const ModHelper& m);
|
||||
ModHelper& operator=(const ModHelper& m);
|
||||
};
|
||||
|
||||
#endif // _MODHELPER_H_
|
|
@ -0,0 +1,76 @@
|
|||
#ifndef _MODULE_H_
|
||||
#define _MODULE_H_
|
||||
|
||||
#include "list.h"
|
||||
#include "config.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
|
||||
enum {
|
||||
ID_UNKNOWN = 0, // "Unknown"
|
||||
ID_HL, // "Halflife"
|
||||
ID_Q1, // "Quake 1"
|
||||
ID_Q2, // "Quake 2"
|
||||
ID_Q3COMP, // "Q3Comp"
|
||||
ID_UT = 5, // "Unreal Tournament"
|
||||
ID_Q3A, // "Quake 3 Arena"
|
||||
ID_EF, // "Elite Force"
|
||||
ID_RTCW, // "Return to Castle Wolfenstein"
|
||||
ID_GS1PROT, // "GSProt"
|
||||
ID_CCR = 10, // "Command & Conquer Renegade"
|
||||
ID_MOHAA, // "Medal of Honor: Allied Assault"
|
||||
ID_JK2, // "Jedi Knight 2"
|
||||
ID_SOF, // "Soldier of Fortune"
|
||||
ID_UT2K3, // "Unreal Tournament 2003"
|
||||
ID_AAO = 15, // "America's Army: Operations"
|
||||
ID_BF1942, // "Battlefield 1942"
|
||||
ID_AVP2, // "Alien vs. Predator 2"
|
||||
ID_RUNE, // "Rune"
|
||||
ID_IGI2, // "Project IGI2: Covert Strike"
|
||||
ID_NWN = 20, // "Never Winter Nights"
|
||||
ID_MOHAA_S, // "Medal of Honor: Allied Assault Spearhead"
|
||||
ID_OPFP, // "Operation Flashpoint"
|
||||
ID_OPFPR, // "Operation Flashpoint Resistance"
|
||||
ID_DEVA, // "Devastation"
|
||||
ID_ET = 25, // "Wolfenstein - Enemy Territory"
|
||||
ID_EF2, // "Elite Force 2"
|
||||
ID_JK3, // "Jedi Knight 3"
|
||||
ID_MOHAA_B, // "Medal of Honor: Allied Assault Breakthrough"
|
||||
ID_TRIBES2, // "Tribes 2"
|
||||
ID_HALO = 30, // "Halo"
|
||||
ID_COD, // "Call of Duty"
|
||||
ID_SAVAGE, // "Savage: The Battle for Newerth"
|
||||
ID_UT2K4, // "Unreal Tournament 2004"
|
||||
ID_HLSTEAM, // "HLSteam"
|
||||
ID_BFV = 35, // "Battlefield Vietnam"
|
||||
ID_GS2PROT, // "GS2Prot"
|
||||
ID_PK, // "Pain Killer"
|
||||
ID_D3, // "Doom 3"
|
||||
ID_OGPPROT, // "OGPProt"
|
||||
ID_HL2 = 40, // "Halflife 2"
|
||||
ID_TRIBES_V, // "Tribes Vengeance"
|
||||
ID_COD_UO, // "Call of Duty: United Offensive"
|
||||
ID_SW_BF, // "Starwars: Battlefront (?)"
|
||||
ID_SWAT4, // "SWAT 4"
|
||||
ID_BF2 = 45, // "Battlefield 2"
|
||||
ID_xxx, // "???"
|
||||
ID_Q4, // "Quake 4"
|
||||
ID_COD2 // "Call of Duty 2"
|
||||
};
|
||||
|
||||
class Module : private ListEntry<Module> {
|
||||
public:
|
||||
virtual ~Module() {};
|
||||
virtual void init(Config* conf) {}
|
||||
virtual void scan(MultiSock* msock) =0;
|
||||
virtual int parse(NetPkt* pkt, GameList* glist) =0;
|
||||
virtual const char* getName() =0;
|
||||
|
||||
protected:
|
||||
Module() {};
|
||||
Module(const Module& m);
|
||||
Module& operator=(const Module& m);
|
||||
};
|
||||
|
||||
#endif // _MODULE_H_
|
|
@ -1,7 +1,27 @@
|
|||
#include "logging.h"
|
||||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "modulelist.h"
|
||||
#include "logging.h"
|
||||
|
||||
ModuleList::ModuleList()
|
||||
ModuleList::ModuleList(Config& conf)
|
||||
: conf(conf)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -13,8 +33,9 @@ ModuleList::~ModuleList()
|
|||
|
||||
void ModuleList::reg(Module* mod)
|
||||
{
|
||||
LogSystem::log(LOG_INFO, "Loading Module '%s'", mod->getName());
|
||||
mlist.addTail(mod);
|
||||
LogSystem::log(LOG_NOTICE, "Registering module '%s'", mod->getName());
|
||||
mod->init(&conf);
|
||||
mlist.add(mod);
|
||||
}
|
||||
|
||||
void ModuleList::scan(MultiSock* msock)
|
||||
|
@ -28,12 +49,12 @@ void ModuleList::scan(MultiSock* msock)
|
|||
|
||||
int ModuleList::parse(NetPkt* pkt, GameList* slist)
|
||||
{
|
||||
int retval = PKT_REJECT;
|
||||
int retval = PARSE_REJECT;
|
||||
|
||||
Iterator<Module> *it = mlist.createIterator();
|
||||
while (it->hasNext()) {
|
||||
retval = it->next()->parse(pkt, slist);
|
||||
if (retval != PKT_REJECT)
|
||||
if (retval != PARSE_REJECT)
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
20
modulelist.h
20
modulelist.h
|
@ -1,27 +1,16 @@
|
|||
#ifndef _MODULELIST_H_
|
||||
#define _MODULELIST_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "multisock.h"
|
||||
#include "netpkt.h"
|
||||
#include "gamelist.h"
|
||||
#include "config.h"
|
||||
|
||||
class Module {
|
||||
public:
|
||||
virtual ~Module() {};
|
||||
|
||||
virtual void scan(MultiSock* msock) =0;
|
||||
virtual int parse(NetPkt* pkt, GameList* slist) =0;
|
||||
virtual char* getName() =0;
|
||||
|
||||
protected:
|
||||
Module() {};
|
||||
};
|
||||
|
||||
#include "module.h"
|
||||
#include "list.h"
|
||||
|
||||
class ModuleList {
|
||||
public:
|
||||
ModuleList();
|
||||
ModuleList(Config& conf);
|
||||
~ModuleList();
|
||||
|
||||
void reg(Module* mod);
|
||||
|
@ -35,6 +24,7 @@ protected:
|
|||
|
||||
private:
|
||||
List<Module> mlist;
|
||||
Config& conf;
|
||||
};
|
||||
|
||||
#endif // _MODULELIST_H_
|
||||
|
|
195
multisock.cpp
195
multisock.cpp
|
@ -1,3 +1,22 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -9,112 +28,17 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "multisock.h"
|
||||
#include "logging.h"
|
||||
|
||||
#define DEFAULT_PORT 7130
|
||||
|
||||
#define DEVFILE "/proc/net/dev"
|
||||
#define BUFSIZE 256
|
||||
|
||||
|
||||
MultiSock::Socket::Socket()
|
||||
{
|
||||
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
LogSystem::log(LOG_CRIT, "Socket: socket()");
|
||||
}
|
||||
|
||||
MultiSock::Socket::~Socket()
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
bool MultiSock::Socket::bindToDevice(const char* name)
|
||||
{
|
||||
strncpy(devname, name, sizeof(devname));
|
||||
|
||||
int ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, devname, sizeof(devname));
|
||||
|
||||
if (ret < 0) {
|
||||
LogSystem::log(LOG_WARNING, "Socket: setsockopt(SO_BINDTODEVICE) %s", devname);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MultiSock::Socket::bindToPort(int port)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
|
||||
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr) != 0) {
|
||||
LogSystem::log(LOG_WARNING, "Socket: ioctl(SIOCGIFADDR) %s", devname);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(&addr, &ifr.ifr_addr, sizeof(addr));
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
LogSystem::log(LOG_WARNING, "Socket: bind() %s", devname);
|
||||
return false;
|
||||
}
|
||||
|
||||
int bcast = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &bcast, sizeof(bcast))) {
|
||||
LogSystem::log(LOG_WARNING, "Socket: setsockopt(SO_BROADCAST) %s", devname);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int MultiSock::Socket::show(char* buf, int size)
|
||||
{
|
||||
return snprintf(buf, size, "%s (%s:%d) ", devname,
|
||||
inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
|
||||
}
|
||||
|
||||
MultiSock::Socket* MultiSock::Socket::createSocket(const char* name, int port)
|
||||
{
|
||||
Socket* sock = new Socket();
|
||||
|
||||
if (sock->fd < 0) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ifreq ifr;
|
||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (ioctl(sock->fd, SIOCGIFFLAGS, &ifr) != 0) {
|
||||
LogSystem::log(LOG_WARNING, "Socket: ioctl(SIOCGIFFLAGS) %s", name);
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(ifr.ifr_flags & IFF_UP) || (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->bindToDevice(name);
|
||||
|
||||
if (!sock->bindToPort(port)) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
MultiSock::MultiSock(Config& conf)
|
||||
{
|
||||
char* buf = (char*)malloc(BUFSIZE);
|
||||
char* buf = new char [BUFSIZE];
|
||||
if (buf == NULL) {
|
||||
LogSystem::log(LOG_CRIT, "MultiSock(): out of memory");
|
||||
return;
|
||||
|
@ -123,34 +47,48 @@ MultiSock::MultiSock(Config& conf)
|
|||
FILE* fp = fopen(DEVFILE, "r");
|
||||
if (fp == NULL) {
|
||||
LogSystem::log(LOG_CRIT, "MultiSock(): can not open " DEVFILE);
|
||||
free(buf);
|
||||
delete [] buf;
|
||||
return;
|
||||
}
|
||||
|
||||
fgets(buf, BUFSIZE, fp);
|
||||
fgets(buf, BUFSIZE, fp);
|
||||
|
||||
int port = conf.getInteger("global", "scan_port", DEFAULT_PORT);
|
||||
FD_ZERO(&fdsel);
|
||||
|
||||
fgets(buf, BUFSIZE, fp);
|
||||
fgets(buf, BUFSIZE, fp);
|
||||
|
||||
int port = conf.getInteger("global", "scan_port", DEFAULT_PORT);
|
||||
Iterator<char>* it = conf.createIterator("global", "scan_deny_iface");
|
||||
|
||||
FD_ZERO(&fdsel);
|
||||
while (fgets(buf, BUFSIZE, fp) != NULL) {
|
||||
char* tok = strtok(buf, " :");
|
||||
|
||||
// TODO: check against config list
|
||||
|
||||
Socket* sock = Socket::createSocket(tok, port);
|
||||
if (sock) {
|
||||
FD_SET(sock->getFD(), &fdsel);
|
||||
|
||||
sock->show(buf, BUFSIZE);
|
||||
LogSystem::log(LOG_NOTICE, "adding Interface %s", buf);
|
||||
|
||||
ifaceList.add(sock);
|
||||
it->reset();
|
||||
while (it->hasNext()) {
|
||||
if (!strcmp(it->next(), tok)) {
|
||||
LogSystem::log(LOG_NOTICE, "Interface '%s' denied by config", tok);
|
||||
tok = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tok) {
|
||||
Socket* sock = Socket::createSocket(tok, port);
|
||||
if (sock) {
|
||||
FD_SET(sock->getFD(), &fdsel);
|
||||
|
||||
sock->show(buf, BUFSIZE);
|
||||
LogSystem::log(LOG_NOTICE, "adding Interface %s", buf);
|
||||
|
||||
ifaceList.add(sock);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete it;
|
||||
|
||||
fclose(fp);
|
||||
free(buf);
|
||||
delete [] buf;
|
||||
|
||||
if (ifaceList.isEmpty())
|
||||
LogSystem::log(LOG_CRIT, "No useable Interfaces found!");
|
||||
}
|
||||
|
||||
MultiSock::~MultiSock()
|
||||
|
@ -159,29 +97,36 @@ MultiSock::~MultiSock()
|
|||
delete ifaceList.get();
|
||||
}
|
||||
|
||||
|
||||
int MultiSock::getRecvSocket()
|
||||
NetPkt* MultiSock::recv()
|
||||
{
|
||||
fd_set fdcpy;
|
||||
|
||||
while (1) {
|
||||
memcpy(&fdcpy, &fdsel, sizeof(fdcpy));
|
||||
|
||||
select(FD_SETSIZE, &fdcpy, NULL, NULL, NULL);
|
||||
|
||||
|
||||
Iterator<Socket>* it = ifaceList.createIterator();
|
||||
while (it->hasNext()) {
|
||||
Socket* sock = it->next();
|
||||
if (FD_ISSET(sock->getFD(), &fdcpy)) {
|
||||
delete it;
|
||||
return sock->getFD();
|
||||
return sock->recv();
|
||||
}
|
||||
}
|
||||
delete it;
|
||||
|
||||
LogSystem::log(LOG_ERROR, "getRecvSocket(): select()");
|
||||
LogSystem::log(LOG_WARN, "MultiSock::recvFrom(): select()");
|
||||
}
|
||||
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int MultiSock::sendto(NetPkt* pkt, struct sockaddr_in* dst)
|
||||
{
|
||||
Iterator<Socket>* it = ifaceList.createIterator();
|
||||
while (it->hasNext())
|
||||
it->next()->sendto(pkt, dst);
|
||||
|
||||
delete it;
|
||||
|
||||
usleep(1000);
|
||||
return 0;
|
||||
}
|
||||
|
|
34
multisock.h
34
multisock.h
|
@ -4,48 +4,24 @@
|
|||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "list.h"
|
||||
#include "config.h"
|
||||
#include "netpkt.h"
|
||||
#include "socket.h"
|
||||
#include "list.h"
|
||||
|
||||
class MultiSock {
|
||||
public:
|
||||
MultiSock(Config& conf);
|
||||
~MultiSock();
|
||||
|
||||
int send(struct in_addr *dstip, int dport, char* data, int size);
|
||||
int getRecvSocket();
|
||||
int sendto(NetPkt* pkt, struct sockaddr_in* dst = NULL);
|
||||
NetPkt* recv();
|
||||
|
||||
protected:
|
||||
MultiSock(const MultiSock& x);
|
||||
MultiSock& operator=(const MultiSock& x);
|
||||
|
||||
private:
|
||||
class Socket {
|
||||
public:
|
||||
static Socket* createSocket(const char* name, int port);
|
||||
int show(char* buf, int size);
|
||||
|
||||
int getFD() { return fd; }
|
||||
|
||||
~Socket();
|
||||
|
||||
protected:
|
||||
Socket(const Socket& s);
|
||||
Socket& operator=(const Socket& s);
|
||||
|
||||
private:
|
||||
Socket();
|
||||
|
||||
bool bindToDevice(const char* name);
|
||||
bool bindToPort(int port);
|
||||
|
||||
int fd;
|
||||
char devname[IFNAMSIZ];
|
||||
struct sockaddr_in addr;
|
||||
};
|
||||
|
||||
void addIface(const char* name, int port);
|
||||
|
||||
List<Socket> ifaceList;
|
||||
fd_set fdsel;
|
||||
};
|
||||
|
|
207
netpkt.cpp
207
netpkt.cpp
|
@ -1,6 +1,31 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// needed for string.h / memmem()
|
||||
#ifndef __USE_GNU
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -8,48 +33,178 @@
|
|||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "netpkt.h"
|
||||
#include "logging.h"
|
||||
|
||||
NetPkt::NetPkt(int size)
|
||||
:size(size)
|
||||
NetPkt::NetPkt(const char* data, int size)
|
||||
: data(data), size(size), alloc(0)
|
||||
{
|
||||
LogSystem::log(LOG_DEBUG, "NetPkt()");
|
||||
data = (char*)malloc(size);
|
||||
}
|
||||
|
||||
NetPkt::NetPkt(int alloc)
|
||||
: size(0), alloc(alloc)
|
||||
{
|
||||
data = new char[alloc];
|
||||
}
|
||||
|
||||
NetPkt::~NetPkt()
|
||||
{
|
||||
free(data);
|
||||
LogSystem::log(LOG_DEBUG, "~NetPkt()");
|
||||
}
|
||||
|
||||
int NetPkt::readFromSocket(int fd)
|
||||
{
|
||||
socklen_t i = sizeof(struct sockaddr_in);
|
||||
return recvfrom(fd, this->data, this->size, 0, (struct sockaddr *)&this->addr, &i);
|
||||
if (alloc > 0)
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
int NetPkt::show(char* buf, int size)
|
||||
{
|
||||
return snprintf(buf, size, "(%s:%d) %d bytes",
|
||||
return snprintf(buf, size, "(%s:%d) (%d/%d) bytes",
|
||||
inet_ntoa(this->addr.sin_addr),
|
||||
ntohs(this->addr.sin_port),
|
||||
this->size);
|
||||
this->size, this->alloc);
|
||||
}
|
||||
|
||||
NetPkt* NetPkt::createFromSocket(int fd)
|
||||
bool NetPkt::compare(unsigned int offset, const char* buf, unsigned int len)
|
||||
{
|
||||
int recvsize = 0;
|
||||
if (offset + len >= this->size)
|
||||
return false;
|
||||
|
||||
if (ioctl(fd, FIONREAD, &recvsize) == -1) {
|
||||
LogSystem::log(LOG_WARNING, "NetPkt::createFromSocket()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NetPkt* retval = new NetPkt(recvsize);
|
||||
retval->readFromSocket(fd);
|
||||
|
||||
return retval;
|
||||
return (memcmp(this->data + offset, buf, len) == 0);
|
||||
}
|
||||
|
||||
int NetPkt::find(unsigned int offset, const char *buf, unsigned int len)
|
||||
{
|
||||
if (offset >= this->size)
|
||||
return -1;
|
||||
|
||||
void* found = memmem(this->data + offset, this->size, buf, len);
|
||||
|
||||
return (found == NULL) ? -1 : ((char*)found - this->data);
|
||||
}
|
||||
|
||||
void NetPkt::setAddress(struct sockaddr_in *tmp)
|
||||
{
|
||||
memcpy(&addr, tmp, sizeof(addr));
|
||||
}
|
||||
|
||||
struct sockaddr_in * NetPkt::getAddress()
|
||||
{
|
||||
return &addr;
|
||||
}
|
||||
|
||||
int NetPkt::parse_int(unsigned int offset, int *val)
|
||||
{
|
||||
const char *max = this->data + this->size;
|
||||
const char *c = this->data + offset;
|
||||
|
||||
/* untere grenze abtesten */
|
||||
if (this->data > c || c > max)
|
||||
return -1;
|
||||
|
||||
*val = 0;
|
||||
|
||||
/* ziffern einlesen */
|
||||
while (isdigit(*c) && c < max)
|
||||
*val = (*val * 10) + (*c++ - 0x30);
|
||||
|
||||
return (c - (this->data + offset));
|
||||
}
|
||||
|
||||
int NetPkt::parse_ip(unsigned int offset, struct in_addr *ip)
|
||||
{
|
||||
int i, tmp, count, pos = offset;
|
||||
ip->s_addr = 0;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
count = this->parse_int(pos, &tmp);
|
||||
pos += count;
|
||||
if (count == 0 || tmp < 0 || tmp > 255)
|
||||
return 0;
|
||||
|
||||
ip->s_addr = ip->s_addr>>8 | tmp<<24;
|
||||
|
||||
if (i != 3 && this->data[pos++] != '.')
|
||||
return 0;
|
||||
}
|
||||
return pos - offset;
|
||||
}
|
||||
|
||||
int NetPkt::getPort()
|
||||
{
|
||||
return ntohs(addr.sin_port);
|
||||
}
|
||||
|
||||
char* NetPkt::showfull()
|
||||
{
|
||||
unsigned int pos = 0, i = 0, j;
|
||||
char *buf = new char[this->size * 4 + 64];
|
||||
|
||||
while (pos < this->size) {
|
||||
i += sprintf(buf + i, "%04X: ", pos);
|
||||
for (j = 0; j < 16; j++) {
|
||||
if (pos + j < this->size)
|
||||
i += sprintf(buf + i, "%02X", (unsigned char)this->data[pos + j]);
|
||||
else
|
||||
i += sprintf(buf + i, " ");
|
||||
|
||||
if (j % 2)
|
||||
buf[i++] = ' ';
|
||||
}
|
||||
|
||||
for (j = 0; j < 16; j++) {
|
||||
if (pos + j < this->size) {
|
||||
unsigned char val = this->data[pos + j];
|
||||
if (val >= 0x20 && val < 0x80)
|
||||
buf[i++] = val;
|
||||
else
|
||||
buf[i++] = '.';
|
||||
} else {
|
||||
buf[i++] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
pos += 16;
|
||||
buf[i++] = '\r';
|
||||
buf[i++] = '\n';
|
||||
}
|
||||
buf[i] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
int NetPkt::getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
bool NetPkt::sameAddress(NetPkt* pkt)
|
||||
{
|
||||
return (this->addr.sin_addr.s_addr == pkt->addr.sin_addr.s_addr) &&
|
||||
(this->addr.sin_port == pkt->addr.sin_port);
|
||||
}
|
||||
|
||||
void NetPkt::merge(NetPkt* pkt)
|
||||
{
|
||||
unsigned int new_alloc = size + pkt->size;
|
||||
|
||||
char* new_data = new char[new_alloc];
|
||||
memcpy(new_data, data, size);
|
||||
|
||||
if (alloc)
|
||||
delete [] data;
|
||||
|
||||
data = new_data;
|
||||
alloc = new_alloc;
|
||||
|
||||
memcpy((void*)(data + size), pkt->data, pkt->size);
|
||||
size += pkt->size;
|
||||
}
|
||||
|
||||
bool NetPkt::append(const char* buf, unsigned int len)
|
||||
{
|
||||
if (alloc < size + len)
|
||||
return false;
|
||||
|
||||
memcpy((void*)(data + size), buf, len);
|
||||
size += len;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
48
netpkt.h
48
netpkt.h
|
@ -4,29 +4,53 @@
|
|||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define PKT_ACCEPT 1
|
||||
#define PKT_ACCEPT_FREED 2
|
||||
#define PKT_REJECT 4
|
||||
#include "list.h"
|
||||
|
||||
class NetPkt {
|
||||
#define PARSE_ACCEPT 1
|
||||
#define PARSE_ACCEPT_FREED 2
|
||||
#define PARSE_ACCEPT_FAKE 3
|
||||
#define PARSE_ACCEPT_QUIRK PARSE_ACCEPT
|
||||
#define PARSE_REJECT 4
|
||||
|
||||
/* avoid cyclic deps */
|
||||
class Socket;
|
||||
|
||||
class NetPkt : private ListEntry<NetPkt> {
|
||||
friend class Socket;
|
||||
public:
|
||||
NetPkt(const char* data, int size);
|
||||
NetPkt(int alloc);
|
||||
~NetPkt();
|
||||
|
||||
static NetPkt* createFromSocket(int fd);
|
||||
NetPkt* append(NetPkt* pkt);
|
||||
int show(char* buf, int size);
|
||||
char* showfull();
|
||||
|
||||
bool compare(unsigned int offset, const char* buf, unsigned int len);
|
||||
int find(unsigned int offset, const char *buf, unsigned int len);
|
||||
|
||||
int parse_int(unsigned int offset, int *val);
|
||||
int parse_ip(unsigned int offset, struct in_addr *ip);
|
||||
|
||||
void setAddress(struct sockaddr_in *addr);
|
||||
struct sockaddr_in * getAddress();
|
||||
bool sameAddress(NetPkt* pkt);
|
||||
|
||||
void merge(NetPkt* pkt);
|
||||
bool append(const char* buf, unsigned int len);
|
||||
|
||||
int getPort();
|
||||
int getSize();
|
||||
|
||||
protected:
|
||||
NetPkt(const NetPkt& x);
|
||||
NetPkt& operator=(const NetPkt& x);
|
||||
|
||||
private:
|
||||
NetPkt(int size);
|
||||
int readFromSocket(int fd);
|
||||
|
||||
struct sockaddr_in addr;
|
||||
int size;
|
||||
char *data;
|
||||
const char *data;
|
||||
unsigned int size;
|
||||
|
||||
private:
|
||||
unsigned int alloc;
|
||||
};
|
||||
|
||||
#endif // _NETPKT_H_
|
||||
|
|
15
recvqueue.h
15
recvqueue.h
|
@ -1,15 +0,0 @@
|
|||
#ifndef _RECVQUEUE_H_
|
||||
#define _RECVQUEUE_H_
|
||||
|
||||
#include "netpkt.h"
|
||||
|
||||
class RecvQueue {
|
||||
public:
|
||||
virtual ~RecvQueue() {};
|
||||
virtual NetPkt* getPkt() =0;
|
||||
|
||||
protected:
|
||||
RecvQueue() {};
|
||||
};
|
||||
|
||||
#endif // _RECVQUEUE_H_
|
11
semaphore.h
11
semaphore.h
|
@ -5,11 +5,12 @@
|
|||
|
||||
class Semaphore {
|
||||
public:
|
||||
Semaphore(int i) { sem_init(&s, 0, i); }
|
||||
~Semaphore() { sem_destroy(&s); }
|
||||
void wait() { sem_wait(&s); }
|
||||
void post() { sem_post(&s); }
|
||||
|
||||
Semaphore() { sem_init(&s, 0, 0); }
|
||||
Semaphore(int i) { sem_init(&s, 0, i); }
|
||||
~Semaphore() { sem_destroy(&s); }
|
||||
void wait() { sem_wait(&s); }
|
||||
void post() { sem_post(&s); }
|
||||
|
||||
protected:
|
||||
Semaphore(const Semaphore& s);
|
||||
Semaphore& operator=(const Semaphore& s);
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "socket.h"
|
||||
#include "logging.h"
|
||||
|
||||
Socket::Socket()
|
||||
{
|
||||
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
LogSystem::log(LOG_CRIT, "Socket: socket()");
|
||||
|
||||
strcpy(devname, "any");
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
}
|
||||
|
||||
Socket::~Socket()
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
bool Socket::checkDeviceFlags(const char* name)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (ioctl(fd, SIOCGIFFLAGS, &ifr) != 0) {
|
||||
LogSystem::log(LOG_WARN, "Socket: ioctl(SIOCGIFFLAGS) %s", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(ifr.ifr_flags & IFF_UP) || (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Socket::bindToDevice(const char* name)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
strncpy(devname, name, sizeof(devname));
|
||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr) != 0) {
|
||||
LogSystem::log(LOG_WARN, "Socket: ioctl(SIOCGIFADDR) %s", devname);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(&addr, &ifr.ifr_addr, sizeof(addr));
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, devname, sizeof(devname)) < 0) {
|
||||
LogSystem::log(LOG_NOTICE, "Socket: setsockopt(SO_BINDTODEVICE) %s", devname);
|
||||
// no failure!
|
||||
//return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Socket::bindToAddress(struct sockaddr_in* tmp)
|
||||
{
|
||||
int i = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0) {
|
||||
LogSystem::log(LOG_NOTICE, "Socket: setsockopt(SO_REUSEADDR) %s", devname);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(&addr, tmp, sizeof(addr));
|
||||
|
||||
if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
LogSystem::log(LOG_WARN, "Socket: bind(%s:%d)",
|
||||
inet_ntoa(addr.sin_addr),
|
||||
ntohs(addr.sin_port));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Socket::setBroadcast(int flag)
|
||||
{
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &flag, sizeof(flag))) {
|
||||
LogSystem::log(LOG_WARN, "Socket: setsockopt(SO_BROADCAST) %s", devname);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Socket* Socket::createSocket(struct sockaddr_in* addr)
|
||||
{
|
||||
Socket* sock = new Socket();
|
||||
|
||||
if (!sock->bindToAddress(addr)) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->setBroadcast(1);
|
||||
return sock;
|
||||
}
|
||||
|
||||
Socket* Socket::createSocket(const char* name, int port)
|
||||
{
|
||||
Socket* sock = new Socket();
|
||||
|
||||
if (!sock->checkDeviceFlags(name)) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!sock->bindToDevice(name)) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->addr.sin_port = htons(port);
|
||||
|
||||
if (!sock->bindToAddress(&sock->addr)) {
|
||||
delete sock;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->setBroadcast(1);
|
||||
return sock;
|
||||
}
|
||||
|
||||
int Socket::show(char* buf, int size)
|
||||
{
|
||||
return snprintf(buf, size, "%s (%s:%d) ", devname,
|
||||
inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
|
||||
}
|
||||
|
||||
int Socket::getRecvSize()
|
||||
{
|
||||
int retval;
|
||||
if (ioctl(fd, FIONREAD, &retval) == -1) {
|
||||
LogSystem::log(LOG_ERROR, "Socket::getRecvSize()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int Socket::getFD() {
|
||||
return fd;
|
||||
}
|
||||
|
||||
int Socket::sendto(NetPkt* pkt, struct sockaddr_in* dst) {
|
||||
if (!dst)
|
||||
dst = &pkt->addr;
|
||||
|
||||
if (::sendto(fd, pkt->data, pkt->size, 0, (struct sockaddr *)dst, sizeof(*dst)) < 0)
|
||||
LogSystem::log(LOG_WARN, "Socket::sendto()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NetPkt* Socket::recv() {
|
||||
fd_set fdsel;
|
||||
|
||||
FD_ZERO(&fdsel);
|
||||
FD_SET(fd, &fdsel);
|
||||
select(FD_SETSIZE, &fdsel, NULL, NULL, NULL);
|
||||
|
||||
NetPkt* pkt = new NetPkt(this->getRecvSize());
|
||||
socklen_t i = sizeof(pkt->addr);
|
||||
pkt->size = ::recvfrom(fd, (void*)pkt->data, pkt->alloc, 0, (struct sockaddr *)&pkt->addr, &i);
|
||||
|
||||
return pkt;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef _SOCKET_H_
|
||||
#define _SOCKET_H_
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "netpkt.h"
|
||||
|
||||
class Socket : private ListEntry<Socket> {
|
||||
public:
|
||||
Socket();
|
||||
~Socket();
|
||||
|
||||
static Socket* createSocket(struct sockaddr_in* addr);
|
||||
static Socket* createSocket(const char* name, int port);
|
||||
|
||||
int show(char* buf, int size);
|
||||
|
||||
int sendto(NetPkt* pkt, struct sockaddr_in* dst = NULL);
|
||||
NetPkt* recv();
|
||||
|
||||
int getFD();
|
||||
|
||||
protected:
|
||||
Socket(const Socket& s);
|
||||
Socket& operator=(const Socket& s);
|
||||
|
||||
private:
|
||||
bool checkDeviceFlags(const char* name);
|
||||
bool bindToDevice(const char* name);
|
||||
bool bindToAddress(struct sockaddr_in* addr);
|
||||
bool setBroadcast(int flag);
|
||||
|
||||
int getRecvSize();
|
||||
|
||||
int fd;
|
||||
char devname[IFNAMSIZ];
|
||||
struct sockaddr_in addr;
|
||||
};
|
||||
|
||||
#endif // _SOCKET_H_
|
25
thread.cpp
25
thread.cpp
|
@ -1,3 +1,22 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "thread.h"
|
||||
|
||||
#define THREAD_STACKSIZE 65536
|
||||
|
@ -16,10 +35,10 @@ Thread::~Thread()
|
|||
switch (state) {
|
||||
case THREAD_RUNNING:
|
||||
cancel();
|
||||
|
||||
|
||||
case THREAD_ENDED:
|
||||
join();
|
||||
|
||||
|
||||
case THREAD_READY:
|
||||
break;
|
||||
}
|
||||
|
@ -31,7 +50,7 @@ int Thread::start(void* arg_)
|
|||
|
||||
if (state != THREAD_READY)
|
||||
return -1;
|
||||
|
||||
|
||||
arg = arg_;
|
||||
state = THREAD_RUNNING;
|
||||
|
||||
|
|
|
@ -1,15 +1,36 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 04/2006 by Olaf Rempel *
|
||||
* razzor@kopf-tisch.de *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <time.h>
|
||||
|
||||
#include "timerservice.h"
|
||||
|
||||
Timer::Timer(Command* cmd, unsigned int timeval)
|
||||
: next(0), cmd(cmd), timeval(timeval)
|
||||
// TODO: how to deregister TimerEvents?
|
||||
|
||||
Timer::Timer(Event* event, unsigned int timeval)
|
||||
: next(0), event(event), timeval(timeval)
|
||||
{
|
||||
}
|
||||
|
||||
Timer::~Timer()
|
||||
{
|
||||
delete cmd;
|
||||
delete event;
|
||||
}
|
||||
|
||||
TimerService::~TimerService()
|
||||
|
@ -39,7 +60,7 @@ void TimerService::checkTimeouts()
|
|||
long now = time(NULL);
|
||||
Timer* search = firstTimer;
|
||||
while (search != NULL && search->timeout <= now) {
|
||||
search->cmd->execute();
|
||||
search->event->execute();
|
||||
|
||||
firstTimer = search->next;
|
||||
addTimer(search, false);
|
||||
|
|
|
@ -3,19 +3,19 @@
|
|||
|
||||
#include "mutex.h"
|
||||
|
||||
class Command {
|
||||
class Event {
|
||||
public:
|
||||
virtual ~Command() {};
|
||||
virtual ~Event() {};
|
||||
virtual void execute() =0;
|
||||
|
||||
protected:
|
||||
Command() {};
|
||||
Event() {};
|
||||
};
|
||||
|
||||
class Timer {
|
||||
friend class TimerService;
|
||||
public:
|
||||
Timer(Command* cmd, unsigned int timeval);
|
||||
Timer(Event* event, unsigned int timeval);
|
||||
~Timer();
|
||||
|
||||
protected:
|
||||
|
@ -24,7 +24,7 @@ protected:
|
|||
|
||||
private:
|
||||
Timer* next;
|
||||
Command* cmd;
|
||||
Event* event;
|
||||
int timeval;
|
||||
long timeout;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue