remove broken plugins
This commit is contained in:
parent
982c2c5e71
commit
acafa13069
|
@ -1,7 +0,0 @@
|
|||
<b>THIS PLUGIN IS CURRENTLY NOT WORKING. WIKILEAF DID A REDESIGN THAT MAKES SCRAPING MORE DIFFICULT AND I HAVE YET TO FIND THE TIME TO FIX IT</B>
|
||||
|
||||
Return strain information from https://www.wikileaf.com/ Seaches powered by Google
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
Usage: strain (strain name)
|
|
@ -1,46 +0,0 @@
|
|||
###
|
||||
# Copyright (c) 2019 oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
"""
|
||||
WikiLeaf: Uses WikiLeaf API to retrieve information
|
||||
"""
|
||||
|
||||
import supybot
|
||||
import supybot.world as world
|
||||
|
||||
# Use this for the version of this plugin. You may wish to put a CVS keyword
|
||||
# in here if you're keeping the plugin in CVS or some similar system.
|
||||
__version__ = ""
|
||||
|
||||
# XXX Replace this with an appropriate author or supybot.Author instance.
|
||||
__author__ = supybot.Author('oddluck', 'oddluck',
|
||||
'oddluck@riseup.net')
|
||||
|
||||
# This is a dictionary mapping supybot.Author instances to lists of
|
||||
# contributions.
|
||||
__contributors__ = {}
|
||||
|
||||
# This is a url where the most recent plugin package can be downloaded.
|
||||
__url__ = 'https://github.com/oddluck/limnoria-plugins/'
|
||||
|
||||
from . import config
|
||||
from . import plugin
|
||||
from imp import reload
|
||||
# In case we're being reloaded.
|
||||
reload(config)
|
||||
reload(plugin)
|
||||
# Add more reloads here if you add third-party modules and want them to be
|
||||
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
||||
|
||||
if world.testing:
|
||||
from . import test
|
||||
|
||||
Class = plugin.Class
|
||||
configure = config.configure
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
|
@ -1,31 +0,0 @@
|
|||
###
|
||||
# Copyright (c) 2019, oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('WikiLeaf')
|
||||
except:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
def configure(advanced):
|
||||
# This will be called by supybot to configure this module. advanced is
|
||||
# a bool that specifies whether the user identified themself as an advanced
|
||||
# user or not. You should effect your configuration by manipulating the
|
||||
# registry as appropriate.
|
||||
from supybot.questions import expect, anything, something, yn
|
||||
conf.registerPlugin('WikiLeaf', True)
|
||||
|
||||
|
||||
WikiLeaf = conf.registerPlugin('WikiLeaf')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
###
|
||||
# Copyright (c) 2019 oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.plugins as plugins
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import requests
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('WikiLeaf')
|
||||
except ImportError:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x: x
|
||||
|
||||
class WikiLeaf(callbacks.Plugin):
|
||||
"""Retrieve Marjuana Strain Information From WikiLeaf"""
|
||||
threaded = True
|
||||
|
||||
def dosearch(self, search):
|
||||
try:
|
||||
searchurl = "https://www.google.com/search?&q={0} site:wikileaf.com/strain/".format(search)
|
||||
ua = UserAgent()
|
||||
header = {'User-Agent':str(ua.random)}
|
||||
data = requests.get(searchurl, headers=header)
|
||||
soup = BeautifulSoup(data.text)
|
||||
elements = soup.select('.r a')
|
||||
url = elements[0]['href']
|
||||
url = re.split('https?://', url)[-1]
|
||||
url = re.sub("&rct=.*", "", url)
|
||||
url = "https://{0}".format(url)
|
||||
except Exception:
|
||||
return
|
||||
else:
|
||||
return url
|
||||
|
||||
def strain(self, irc, msg, args, strain):
|
||||
"""<strain>
|
||||
Returns strain information from WikiLeaf. Search powered by Google.
|
||||
"""
|
||||
try:
|
||||
url = self.dosearch(strain)
|
||||
except Exception:
|
||||
irc.reply("No results found, what have you been smoking?")
|
||||
else:
|
||||
try:
|
||||
ua = UserAgent()
|
||||
header = {'User-Agent':str(ua.random)}
|
||||
data = requests.get(url, headers=header)
|
||||
soup = BeautifulSoup(data.text)
|
||||
name = re.sub('\s+', ' ', soup.find("h1", itemprop="name").getText())
|
||||
straininfo = re.sub('\s+', ' ', soup.find("div", class_="product-info-line cannabis").getText())
|
||||
description = re.sub('\s+', ' ', soup.find("div", itemprop="description").getText())
|
||||
thc = re.sub('\s+', ' ', soup.find_all("div", class_="product-container-header cf")[1].getText())
|
||||
reply = "\x02{0}\x0F | {1} | {2} | {3}".format(name.strip(), straininfo.strip(), thc.strip(), description.strip())
|
||||
del data, soup
|
||||
irc.reply(reply)
|
||||
irc.reply(url)
|
||||
except Exception:
|
||||
irc.reply("Unable to retrieve info from {0}".format(url))
|
||||
|
||||
strain = wrap(strain, ['text'])
|
||||
|
||||
Class = WikiLeaf
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
requests
|
||||
beautifulsoup4
|
||||
fake_useragent
|
|
@ -1,16 +0,0 @@
|
|||
###
|
||||
# Copyright (c) 2019, oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
|
||||
class WikiLeafTestCase(PluginTestCase):
|
||||
plugins = ('WikiLeaf',)
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
339
suds/COPYING.txt
339
suds/COPYING.txt
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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) year 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 Lesser General
|
||||
Public License instead of this License.
|
117
suds/README.md
117
suds/README.md
|
@ -1,117 +0,0 @@
|
|||
# Suds from /r/openttd
|
||||
### A Supybot Plugin for communicating with OpenTTD servers via the AdminPort interface
|
||||
____
|
||||
|
||||
This plugin is released under the GPL, a copy of which has been included in COPYING.txt
|
||||
____
|
||||
|
||||
#### Prerequisites
|
||||
* working OpenTTD server (optionally OFS installed and configured)
|
||||
* Supybot set up in a channel
|
||||
* libottdadmin2 by Xaroth installed
|
||||
|
||||
Supybot comes with its own installation instructions. Those and its user manual
|
||||
can be found here: http://sourceforge.net/projects/supybot/
|
||||
|
||||
OFS (Openttd File Scripts) can be obtained here: http://dev.openttdcoop.org/projects/ofs
|
||||
It simply needs to be copied to a directory on the same user@host as that
|
||||
OpenTTD server, and configured. See the included readme.txt for details. If the
|
||||
server is located on a different user@host from the bot, you will need to give
|
||||
the user running the bot password-less ssh access to the user@host. This allows
|
||||
the bot to eg download a savegame to the server.
|
||||
|
||||
###### Installing libottdadmin2:
|
||||
First go to https://github.com/Xaroth/libottdadmin2 and either download the zip
|
||||
or git clone. Now there are 2 ways you can install this lib:
|
||||
|
||||
The first one is the easiest one, run `python2 setup.py install` from the
|
||||
libottdadmin2 dir. This will install the lib systemwide and make it available
|
||||
to any other python programs that may need it. You may need sudo access
|
||||
depending on the system setup though.
|
||||
|
||||
The other way is to copy the libottdadmin2 dir into the Soap plugin directory.
|
||||
Copied right client.py should be found at this path:
|
||||
`<PathToPlugins>/Soap/libottdadmin2/client.py`
|
||||
This will give the same functionality, but only for the Soap plugin. On the
|
||||
upside, no sudo access required.
|
||||
|
||||
____
|
||||
|
||||
#### Installation
|
||||
|
||||
To install Soap, simply copy the Soap directory into the bots plugin directory,
|
||||
and load the plugin once the bot is running.
|
||||
#### Configuration
|
||||
|
||||
Configuration is handled via supybot's config command. First thing you want to
|
||||
configure is the default settings. Soap can handle multiple game-servers, but
|
||||
is bound to 1 server per irc-channel.
|
||||
|
||||
Correct format for config would be `config plugins.Soap.<setting> <value>` - for example, `config plugins.Soap.host 127.0.0.1`
|
||||
|
||||
This will set the default for any new server to 127.0.0.1
|
||||
|
||||
To change a setting for one server only, you want to specify the channel: `config channel [#yourchan] plugins.Soap.<setting> <value>`
|
||||
|
||||
#yourchannel is optional when used in the channel (it will use the current
|
||||
channel), but required when used in queries. You'll want to use the latter method
|
||||
for setting the password. Example: `config channel #mychannel supybot.plugins.Soap.host 127.0.0.1` can be used anywhere the bot is, whilst `config channel plugins.Soap.host 127.0.0.1` will change the host for channel the command was issued in.
|
||||
|
||||
Finally, you want to activate the channels by configuring the list of
|
||||
channels. This is a global value, so theres only one variation: `config plugins.Soap.channels #mychannel #myotherchannel ...`, which will enable below commands for servers tied to those channels. Changing this
|
||||
setting will require reloading the plugin so that it can set up all the connections correctly.
|
||||
|
||||
If you didn't specify any settings for a channel, it will pick the default setting instead.
|
||||
This also means, that if you want one setting to apply to all the servers (eg you run
|
||||
all on a non-standard adminport), simply change the option as if it were a global
|
||||
setting.
|
||||
|
||||
For a description of the individual variables, see config.py.
|
||||
|
||||
## Command List
|
||||
|
||||
Op/Trusted-only commands:
|
||||
* `apconnect` - connects to the openttd server
|
||||
* `apdisconnect` - disconnects from same
|
||||
* `pause` - manually pauses the game
|
||||
* `unpause` - manually unpauses the game (sets min_active_clients to 0)
|
||||
* `auto` - turns on autopause, and re-sets min_active_clients to theconfigured amount
|
||||
* `rcon` - sends an rcon command to the server
|
||||
* `players` - lists the clients connected to the server
|
||||
* `content` - updates the downloaded content from bananas
|
||||
* `contentupdate` - performs 'content update'. use this before using the 'content' command
|
||||
* `rescan` - rescans the content_download directory for new files. (May cause users to get disconnected)
|
||||
* `save` - saves the game to game.sav
|
||||
* `transfer` - transfers savegame to a web-accessible directory (usage: !transfer number savegame)
|
||||
|
||||
Commands requiring op/trusted and OFS installed
|
||||
* `getsave` - download savegame from url
|
||||
* `start` - starts OpenTTD dedicated server
|
||||
* `update` - updates the OpenTTD server and (re)starts it
|
||||
|
||||
Publicly available commands
|
||||
* `playercount` - shows how many people are playing
|
||||
* `companies` - lists companies
|
||||
* `date` - returns the ingame date
|
||||
* `ding` - should be ping, but that command was taken. Dings the server
|
||||
* `help` - links to http://wiki.openttdcoop.org/Soap
|
||||
* `info` - shows some basic info about the server
|
||||
* `ip` - replies with the address needed to join the server as a player
|
||||
* `password` - shows the current password needed to join the server
|
||||
* `revision` - shows current revision of the OpenTTD server
|
||||
* `vehicles` - totals each vehicle type in the game
|
||||
|
||||
These commands can also be called with channel or serverID as parameter. This can
|
||||
be handy when you want to command a server from a different channel or from
|
||||
private message.
|
||||
|
||||
There are also 3 ingame commands:
|
||||
* `!admin` - sends a message to irc requesting admins look at the server
|
||||
* `!nick <newnick>` - will change the ingame nick of the caller
|
||||
* `!rules` - replies with an url pointing to the rules for playing
|
||||
|
||||
|
||||
### Credit where credit is due
|
||||
* Taede Werkhoven: For writing SOAP, which this plugin is derived from
|
||||
* Xaroth: For writing libottdadmin2
|
||||
* Dihedral: generated passwords.txt from OpenTTD source
|
|
@ -1,66 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
"""
|
||||
lets the bot communicate with openttd via its adminport, and to control same
|
||||
"""
|
||||
|
||||
import supybot
|
||||
import supybot.world as world
|
||||
|
||||
# Use this for the version of this plugin. You may wish to put a CVS keyword
|
||||
# in here if you're keeping the plugin in CVS or some similar system.
|
||||
__version__ = ""
|
||||
|
||||
# XXX Replace this with an appropriate author or supybot.Author instance.
|
||||
__author__ = supybot.Author('Taede Werkhoven', 'TWerkhoven', 't.werkhoven@turbulent-t.com')
|
||||
__maintainer__ = getattr(supybot.authors, 'oddluck',
|
||||
supybot.Author('oddluck', 'oddluck', 'oddluck@riseup.net'))
|
||||
|
||||
# This is a dictionary mapping supybot.Author instances to lists of
|
||||
# contributions.
|
||||
__contributors__ = {}
|
||||
|
||||
# This is a url where the most recent plugin package can be downloaded.
|
||||
__url__ = 'https://github.com/oddluck/limnoria-plugins/'
|
||||
|
||||
|
||||
import config
|
||||
import enums
|
||||
import soaputils
|
||||
import soapclient
|
||||
import libottdadmin2
|
||||
import plugin
|
||||
reload(config)
|
||||
reload(enums)
|
||||
reload(soaputils)
|
||||
reload(soapclient)
|
||||
reload(libottdadmin2)
|
||||
reload(plugin)
|
||||
|
||||
# In case we're being reloaded.
|
||||
# Add more reloads here if you add third-party modules and want them to be
|
||||
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
||||
|
||||
if world.testing:
|
||||
import test
|
||||
|
||||
Class = plugin.Class
|
||||
configure = config.configure
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
138
suds/config.py
138
suds/config.py
|
@ -1,138 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
import re
|
||||
|
||||
class SemicolonSeparatedListOfStrings(registry.SeparatedListOf):
|
||||
Value = registry.String
|
||||
def splitter(self, s):
|
||||
return re.split(r'\s*;\s*', s)
|
||||
joiner = '; '.join
|
||||
|
||||
|
||||
def configure(advanced):
|
||||
# This will be called by supybot to configure this module. advanced is
|
||||
# a bool that specifies whether the user identified himself as an advanced
|
||||
# user or not. You should effect your configuration by manipulating the
|
||||
# registry as appropriate.
|
||||
from supybot.questions import expect, anything, something, yn
|
||||
conf.registerPlugin('suds', True)
|
||||
|
||||
|
||||
Suds = conf.registerPlugin('suds')
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(Suds, 'someConfigVariableName',
|
||||
# registry.Boolean(False, """Help for someConfigVariableName."""))
|
||||
|
||||
|
||||
# General configuration settings
|
||||
conf.registerGlobalValue(Suds, 'channels',
|
||||
registry.SpaceSeparatedListOfStrings('', """ The channels you wish to use
|
||||
for OpenTTD communication """))
|
||||
conf.registerGlobalValue(Suds, 'logdir',
|
||||
registry.String('None', """ Logging directory. This is where logfiles are
|
||||
saved to. It will rotate logs when a new game starts, and back up the old
|
||||
log. A maximum of 2 logs are backed up. To disable logging, set this to an
|
||||
invalid path or 'None' """))
|
||||
conf.registerGlobalValue(Suds, 'logHistory',
|
||||
registry.Integer(2, """ Amount of logfiles to keep. This does not include
|
||||
the current logfile. A value of 2 will keep the current logfile, and the 2
|
||||
preceding ones as .log.1 and .log.2."""))
|
||||
|
||||
# OpenTTD server configuration
|
||||
conf.registerChannelValue(Suds, 'serverID',
|
||||
registry.String('default', """ Optional hort name for the server, used for
|
||||
issuing commands via query. no spaces allowed. Should be unique to each
|
||||
server when managing multiple game-servers """))
|
||||
conf.registerChannelValue(Suds, 'host',
|
||||
registry.String('127.0.0.1', """ The hostname or IP-adress of the OpenTTD
|
||||
server you wish the bot to connect to """))
|
||||
conf.registerChannelValue(Suds, 'port',
|
||||
registry.Integer(3977, """ The port of the server's adminport """))
|
||||
conf.registerChannelValue(Suds, 'password',
|
||||
registry.String('password', """ The password as set in openttd.cfg """))
|
||||
conf.registerChannelValue(Suds, 'publicAddress',
|
||||
registry.String('openttd.example.org', """ Address players use to connect
|
||||
to the server """))
|
||||
|
||||
# File-related settings
|
||||
conf.registerChannelValue(Suds, 'ofslocation',
|
||||
registry.String('/home/openttdserver/', """ Location of OpenTTD File Scripts
|
||||
(OFS). This can either be a local directory (/path/to/ofs/{OFS}) or in the form of
|
||||
'ssh -p23 user@host:/path/to/ofs/{OFS}'. In the latter case, make sure to set up
|
||||
the bot-user to have password-less login to the machine with ofs/openttd. Put
|
||||
{OFS} wher the actual ofs-command should go. """))
|
||||
|
||||
# Miscellanious server-specific settings
|
||||
conf.registerChannelValue(Suds, 'autoConnect',
|
||||
registry.Boolean(False, """ Setting this to True will cause the bot to
|
||||
attempt to connect to OpenTTD automatically """))
|
||||
conf.registerChannelValue(Suds, 'allowOps',
|
||||
registry.Boolean(True, """ Setting this to True will allow any op as well
|
||||
as trusted user in the channel to execute soap commands . Setting this to
|
||||
False only allows trusted users to do so """ ))
|
||||
conf.registerChannelValue(Suds, 'minPlayers',
|
||||
registry.Integer(0, """ The defalt minimum number of players for the server
|
||||
to unpause itself. 0 means game never pauses unless manually paused """))
|
||||
conf.registerChannelValue(Suds, 'checkClientVPN',
|
||||
registry.Boolean(False, """ True means players will have their IP checked for
|
||||
known VPN or other such ban evasion techniques, and kicked if they are using them."""))
|
||||
conf.registerGlobalValue(Suds, 'checkClientVPNWhitelist',
|
||||
SemicolonSeparatedListOfStrings('', """If checkClientVPN is enabled, you can disable checking certain IPs here. Semicolon delimited."""))
|
||||
conf.registerGlobalValue(Suds, 'nameBlacklist',
|
||||
SemicolonSeparatedListOfStrings('', """List of player names to autokick. Semicolon delimited."""))
|
||||
conf.registerChannelValue(Suds, 'playAsPlayer',
|
||||
registry.Boolean(True, """ True means players can play with Player as their
|
||||
name. False will get them moved to spectators any time they try to join a
|
||||
company, and eventually kicked """))
|
||||
conf.registerChannelValue(Suds, 'playerKickCount',
|
||||
registry.Integer(3, """ The number of times a player can attempt to join
|
||||
a company before they are automatically kicked. Setting to 0 will kick
|
||||
on the first infraction. """))
|
||||
conf.registerChannelValue(Suds, 'passwordInterval',
|
||||
registry.Integer(0, """ Interval in seconds between soap changing the
|
||||
password clients use to join the server. Picks a random line from the
|
||||
included passwords.txt. If you don't want your server to have random
|
||||
passwords, leave this set at 0. People can use the password command to find
|
||||
the current password """))
|
||||
conf.registerChannelValue(Suds, 'welcomeMessage',
|
||||
SemicolonSeparatedListOfStrings('', """ Welcome message to be sent to
|
||||
players when they connect. Separate lines with semicolons. to insert (for
|
||||
instance) the client name, put {clientname} in the string, including the {}.
|
||||
Valid replacements are: {clientname} {servername} and {serverversion}. Set
|
||||
this to 'None' to disable on-join welcome messages """))
|
||||
conf.registerChannelValue(Suds, 'defaultSettings',
|
||||
registry.String('', """ This should be an absolute path pointing to a textfile
|
||||
containing one command per line. This file is read by the setdef command, and
|
||||
all commands are executed """))
|
||||
|
||||
# various URL's
|
||||
conf.registerChannelValue(Suds, 'downloadUrl',
|
||||
registry.String('None', """ Custom download url. Use only if using a custom version
|
||||
that cannot be obtained from openttd.org. Soap will automatically generate url's
|
||||
for openttd stable and nightly versions."""))
|
||||
conf.registerChannelValue(Suds, 'rulesUrl',
|
||||
registry.String('None', """ Url where the rules for the server can be found.
|
||||
Set to 'None' to disable the ingame and irc !rules commands. """))
|
||||
conf.registerChannelValue(Suds, 'saveUrl',
|
||||
registry.String('None', """ Url where savegames will be available after
|
||||
using the transfer command. enter the full url, including the filename. Use
|
||||
{ID} where the game number goes"""))
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
|
@ -1,43 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
from libottdadmin2.enums import EnumHelper
|
||||
|
||||
class ConnectionState(EnumHelper):
|
||||
DISCONNECTED = 0x00
|
||||
CONNECTING = 0x01
|
||||
AUTHENTICATING = 0x02
|
||||
CONNECTED = 0x03
|
||||
DISCONNECTING = 0x04
|
||||
SHUTDOWN = 0x05
|
||||
|
||||
class PauseState(EnumHelper):
|
||||
UNPAUSED = 0x00 # Unpaused
|
||||
PAUSED_NORMAL = 0x01 # Paused manually
|
||||
PAUSED_SAVELOAD = 0x02 # Paused for saving/loading
|
||||
PAUSED_JOIN = 0x04 # Pause on join
|
||||
PAUSED_ERROR = 0x08 # Pause because of a (critical) error
|
||||
PAUSED_ACTIVE_CLIENTS = 0x10 # Pause for 'min_active_clients'
|
||||
PAUSED_GAMESCRIPT = 0x20 # Paused by game script
|
||||
|
||||
class RconStatus(EnumHelper):
|
||||
IDLE = 0x00 # We are not processing any rcon commands
|
||||
ACTIVE = 0x01 # We are awayting rcon results
|
||||
CHANNEL = 0x02 # Automatic rcon command has output for the channel
|
||||
SHUTDOWNSAVED = 0x03 # Game has been saved by the shutdown command, no output
|
||||
UPDATESAVED = 0x04 # Game has been saved prior to shutting down for update, no output
|
||||
RESTARTSAVED = 0x05 # Game has been saved prior to restarting, no output
|
1107
suds/passwords.txt
1107
suds/passwords.txt
File diff suppressed because it is too large
Load Diff
1728
suds/plugin.py
1728
suds/plugin.py
File diff suppressed because it is too large
Load Diff
|
@ -1,220 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
import logging
|
||||
import Queue
|
||||
|
||||
from libottdadmin2.trackingclient import TrackingAdminClient
|
||||
from libottdadmin2.event import Event
|
||||
from libottdadmin2.enums import UpdateType, UpdateFrequency
|
||||
|
||||
from enums import RconStatus, ConnectionState
|
||||
|
||||
class SoapEvents(object):
|
||||
def __init__(self):
|
||||
self.connected = Event()
|
||||
self.disconnected = Event()
|
||||
|
||||
self.shutdown = Event()
|
||||
self.new_game = Event()
|
||||
|
||||
self.new_map = Event()
|
||||
# self.protocol = Event()
|
||||
|
||||
# self.datechanged = Event()
|
||||
|
||||
# self.clientinfo = Event()
|
||||
self.clientjoin = Event()
|
||||
self.clientupdate = Event()
|
||||
self.clientquit = Event()
|
||||
|
||||
# self.companyinfo = Event()
|
||||
# self.companynew = Event()
|
||||
# self.companyupdate = Event()
|
||||
# self.companyremove = Event()
|
||||
# self.companystats = Event()
|
||||
# self.companyeconomy = Event()
|
||||
|
||||
self.chat = Event()
|
||||
self.rcon = Event()
|
||||
self.rconend = Event()
|
||||
self.console = Event()
|
||||
self.cmdlogging = Event()
|
||||
|
||||
self.pong = Event()
|
||||
|
||||
class SoapClient(TrackingAdminClient):
|
||||
|
||||
|
||||
|
||||
# Initialization & miscellanious functions
|
||||
|
||||
def __init__(self, channel, serverid, events = None):
|
||||
super(SoapClient, self).__init__(events)
|
||||
self.channel = channel
|
||||
self.ID = serverid
|
||||
self.soapEvents = SoapEvents()
|
||||
self._attachEvents()
|
||||
self.logger = logging.getLogger('Soap-%s' % self.ID)
|
||||
self.logger.setLevel(logging.INFO)
|
||||
|
||||
self.rconCommands = Queue.Queue()
|
||||
self.rconNick = None
|
||||
self.rconResults = {}
|
||||
self.rconState = RconStatus.IDLE
|
||||
|
||||
self.connectionstate = ConnectionState.DISCONNECTED
|
||||
self.registered = False
|
||||
self.filenumber = None
|
||||
|
||||
self.clientPassword = None
|
||||
|
||||
def _attachEvents(self):
|
||||
self.events.connected += self._rcvConnected
|
||||
self.events.disconnected += self._rcvDisconnected
|
||||
|
||||
self.events.shutdown += self._rcvShutdown
|
||||
self.events.new_game += self._rcvNewGame
|
||||
|
||||
self.events.new_map += self._rcvNewMap
|
||||
|
||||
self.events.clientjoin += self._rcvClientJoin
|
||||
self.events.clientupdate += self._rcvClientUpdate
|
||||
self.events.clientquit += self._rcvClientQuit
|
||||
|
||||
self.events.chat += self._rcvChat
|
||||
self.events.rcon += self._rcvRcon
|
||||
self.events.rconend += self._rcvRconEnd
|
||||
self.events.console += self._rcvConsole
|
||||
self.events.cmdlogging += self._rcvCmdLogging
|
||||
|
||||
self.events.pong += self._rcvPong
|
||||
|
||||
def copy(self):
|
||||
obj = SoapClient(self._channel, self._ID, self.events)
|
||||
for prop in self._settable_args:
|
||||
setattr(obj, prop, getattr(self, prop, None))
|
||||
return obj
|
||||
|
||||
|
||||
|
||||
# Insert connection info into parameters
|
||||
|
||||
def _rcvConnected(self):
|
||||
self.registered = True
|
||||
self.soapEvents.connected(self.channel)
|
||||
|
||||
def _rcvDisconnected(self, canRetry):
|
||||
self.registered = False
|
||||
self.soapEvents.disconnected(self.channel, canRetry)
|
||||
|
||||
def _rcvShutdown(self):
|
||||
self.soapEvents.shutdown(self.channel)
|
||||
|
||||
def _rcvNewGame(self):
|
||||
self.soapEvents.new_game(self.channel)
|
||||
|
||||
def _rcvNewMap(self, mapinfo, serverinfo):
|
||||
self.soapEvents.new_map(self.channel, mapinfo, serverinfo)
|
||||
|
||||
def _rcvClientJoin(self, client):
|
||||
self.soapEvents.clientjoin(self.channel, client)
|
||||
|
||||
def _rcvClientUpdate(self, old, client, changed):
|
||||
self.soapEvents.clientupdate(self.channel, old, client, changed)
|
||||
|
||||
def _rcvClientQuit(self, client, errorcode):
|
||||
self.soapEvents.clientquit(self.channel, client, errorcode)
|
||||
|
||||
def _rcvChat(self, **kwargs):
|
||||
data = dict(kwargs.items())
|
||||
data['connChan'] = self.channel
|
||||
self.soapEvents.chat(**data)
|
||||
|
||||
def _rcvRcon(self, result, colour):
|
||||
self.soapEvents.rcon(self.channel, result, colour)
|
||||
|
||||
def _rcvRconEnd(self, command):
|
||||
self.soapEvents.rconend(self.channel, command)
|
||||
|
||||
def _rcvConsole(self, message, origin):
|
||||
self.soapEvents.console(self.channel, origin, message)
|
||||
|
||||
def _rcvCmdLogging(self, **kwargs):
|
||||
data = dict(kwargs.items())
|
||||
data['connChan'] = self.channel
|
||||
self.soapEvents.cmdlogging(**data)
|
||||
|
||||
def _rcvPong(self, start, end, delta):
|
||||
self.soapEvents.pong(self.channel, start, end, delta)
|
||||
|
||||
|
||||
|
||||
# Store some extra info
|
||||
|
||||
_settable_args = TrackingAdminClient._settable_args + ['irc', 'ID', 'channel', 'debugLog']
|
||||
_irc = None
|
||||
_ID = 'Default'
|
||||
_channel = None
|
||||
_debugLog = False
|
||||
|
||||
@property
|
||||
def channel(self):
|
||||
return self._channel
|
||||
|
||||
@channel.setter
|
||||
def channel(self, value):
|
||||
self._channel = value.lower()
|
||||
|
||||
@property
|
||||
def irc(self):
|
||||
return self._irc
|
||||
|
||||
@irc.setter
|
||||
def irc(self, value):
|
||||
self._irc = value
|
||||
|
||||
@property
|
||||
def ID(self):
|
||||
return self._ID
|
||||
|
||||
@ID.setter
|
||||
def ID(self, value):
|
||||
self._ID = value.lower()
|
||||
|
||||
@property
|
||||
def debugLog(self):
|
||||
return self._debugLog
|
||||
|
||||
@debugLog.setter
|
||||
def debugLog(self, value):
|
||||
self._debugLog = value
|
||||
if self._debugLog:
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
else:
|
||||
self.logger.setLevel(logging.INFO)
|
||||
|
||||
update_types = [
|
||||
(UpdateType.CLIENT_INFO, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.COMPANY_INFO, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.COMPANY_ECONOMY, UpdateFrequency.WEEKLY),
|
||||
(UpdateType.COMPANY_STATS, UpdateFrequency.WEEKLY),
|
||||
(UpdateType.CHAT, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.CONSOLE, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.LOGGING, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.DATE, UpdateFrequency.DAILY),
|
||||
]
|
|
@ -1,391 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.ircdb as ircdb
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import supybot.ircutils as ircutils
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os.path
|
||||
import re
|
||||
import urllib2
|
||||
import requests
|
||||
import sys
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from enums import *
|
||||
from libottdadmin2.enums import Colour, Action, DestType, ClientID
|
||||
from libottdadmin2.packets.admin import AdminRcon, AdminChat
|
||||
from libottdadmin2.trackingclient import MappingObject
|
||||
|
||||
class RconResults(MappingObject):
|
||||
_mapping = [
|
||||
('irc', 'irc'),
|
||||
('command', 'command'),
|
||||
('succestext', 'succestext'),
|
||||
('results', 'results'),
|
||||
]
|
||||
|
||||
def checkPermission(irc, msg, channel, allowOps):
|
||||
capable = ircdb.checkCapability(msg.prefix, 'trusted')
|
||||
if capable:
|
||||
return True
|
||||
else:
|
||||
opped = msg.nick in irc.state.channels[channel].ops
|
||||
if opped and allowOps:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def disconnect(conn, forced):
|
||||
if forced:
|
||||
conn.force_disconnect()
|
||||
else:
|
||||
conn.disconnect()
|
||||
|
||||
def generateDownloadUrl(irc, version, osType = None):
|
||||
stable = '\d\.\d\.\d'
|
||||
testing = '\d\.\d\.\d-rc\d'
|
||||
trunk = 'r\d{5}'
|
||||
|
||||
if not osType:
|
||||
url = 'http://www.openttd.org/en/'
|
||||
if re.match(stable, version) or re.match(testing, version):
|
||||
url += 'download-stable/%s' % version
|
||||
elif re.match(trunk, version):
|
||||
url += 'download-trunk/%s' % version
|
||||
else:
|
||||
url = None
|
||||
else:
|
||||
url = 'http://binaries.openttd.org/'
|
||||
if re.match(stable, version):
|
||||
url += 'releases/%s/openttd-%s-' % (version, version)
|
||||
elif re.match(trunk, version):
|
||||
url += 'nightlies/trunk/%s/openttd-trunk-%s-' % (version, version)
|
||||
else:
|
||||
url = None
|
||||
if url:
|
||||
if osType.startswith('lin'):
|
||||
url += 'linux-generic-'
|
||||
if osType == 'lin':
|
||||
url += 'i686.tar.xz'
|
||||
elif osType == 'lin64':
|
||||
url += 'amd64.tar.xz'
|
||||
else:
|
||||
url = None
|
||||
elif osType == 'osx':
|
||||
url += 'macosx-universal.zip'
|
||||
elif osType == 'source':
|
||||
url += 'source.tar.xz'
|
||||
elif osType.startswith('win'):
|
||||
url += 'windows-%s.zip' % osType
|
||||
else:
|
||||
url = None
|
||||
return url
|
||||
|
||||
def getColourNameFromNumber(number):
|
||||
colours = {
|
||||
Colour.COLOUR_DARK_BLUE : 'Dark Blue',
|
||||
Colour.COLOUR_PALE_GREEN : 'Pale Green',
|
||||
Colour.COLOUR_PINK : 'Pink',
|
||||
Colour.COLOUR_YELLOW : 'Yellow',
|
||||
Colour.COLOUR_RED : 'Red',
|
||||
Colour.COLOUR_LIGHT_BLUE : 'Light Blue',
|
||||
Colour.COLOUR_GREEN : 'Green',
|
||||
Colour.COLOUR_DARK_GREEN : 'Dark Green',
|
||||
Colour.COLOUR_BLUE : 'Blue',
|
||||
Colour.COLOUR_CREAM : 'Cream',
|
||||
Colour.COLOUR_MAUVE : 'Mauve',
|
||||
Colour.COLOUR_PURPLE : 'Purple',
|
||||
Colour.COLOUR_ORANGE : 'Orange',
|
||||
Colour.COLOUR_BROWN : 'Brown',
|
||||
Colour.COLOUR_GREY : 'Grey',
|
||||
Colour.COLOUR_WHITE : 'White',
|
||||
}
|
||||
colourName = colours.get(number, number)
|
||||
return colourName
|
||||
|
||||
def getQuitReasonFromNumber(number):
|
||||
reasons = {
|
||||
0x00 :'general error',
|
||||
0x01 :'desync error',
|
||||
0x02 :'could not load map',
|
||||
0x03 :'connection lost',
|
||||
0x04 :'protocol error',
|
||||
0x05 :'NewGRF mismatch',
|
||||
0x06 :'not authorized',
|
||||
0x07 :'received invalid or unexpected packet',
|
||||
0x08 :'wrong revision',
|
||||
0x09 :'name already in use',
|
||||
0x0A :'wrong password',
|
||||
0x0B :'wrong company in DoCommand',
|
||||
0x0C :'kicked by server',
|
||||
0x0D :'was trying to use a cheat',
|
||||
0x0E :'server full',
|
||||
0x0F :'was sending too many commands',
|
||||
0x10 :'received no password in time',
|
||||
0x11 :'general timeout',
|
||||
0x12 :'downloading map took too long',
|
||||
0x13 :'processing map took too long',
|
||||
}
|
||||
reasonText = reasons.get(number, number)
|
||||
return reasonText
|
||||
|
||||
def getConnection(connections, channels, source, serverID = None):
|
||||
conn = None
|
||||
|
||||
if not serverID:
|
||||
if ircutils.isChannel(source) and source.lower() in channels:
|
||||
conn = connections.get(source)
|
||||
else:
|
||||
if ircutils.isChannel(serverID):
|
||||
conn = connections.get(serverID)
|
||||
|
||||
serverID = serverID and serverID.lower() or 'default'
|
||||
|
||||
if not conn:
|
||||
for c in connections.itervalues():
|
||||
if c.ID == serverID:
|
||||
conn = c
|
||||
|
||||
return conn
|
||||
|
||||
def getConnectionID(conn):
|
||||
if conn.ID == 'default':
|
||||
return conn.channel
|
||||
else:
|
||||
return conn.ID
|
||||
|
||||
def initLogger(conn, logdir, history):
|
||||
if os.path.isdir(logdir):
|
||||
if not len(conn.logger.handlers):
|
||||
logfile = os.path.join(logdir, '%s.log' % conn.ID)
|
||||
logformat = logging.Formatter('%(asctime)s %(message)s')
|
||||
handler = logging.handlers.RotatingFileHandler(logfile, backupCount = history)
|
||||
handler.setFormatter(logformat)
|
||||
conn.logger.addHandler(handler)
|
||||
|
||||
def logEvent(logger, message):
|
||||
try:
|
||||
logger.info(message)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def msgChannel(irc, channel, msg):
|
||||
if channel in irc.state.channels or irc.isNick(channel):
|
||||
irc.queueMsg(ircmsgs.privmsg(channel, msg))
|
||||
|
||||
def checkIP(irc, conn, client, whitelist, checkedDict):
|
||||
|
||||
if client.hostname in whitelist:
|
||||
text = '*** {name} is a whitelisted player, and will not be checked.'.format(name=client.name)
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
return
|
||||
result = None
|
||||
|
||||
# First let's garbage collect
|
||||
# learner's note: you can't just do iteritems() into a del because you'll get a RuntimeError exception when
|
||||
# the dictionary changes size during the loop
|
||||
cutoff = datetime.utcnow() - timedelta(days=1)
|
||||
checkedDict = { k:v for k,v in checkedDict.iteritems() if v.get('timestamp') < cutoff }
|
||||
|
||||
if client.hostname not in checkedDict \
|
||||
or not checkedDict.get(client.hostname, {}).get('message', False):
|
||||
try:
|
||||
result = requests.get("http://check.getipintel.net/check.php?ip=" + client.hostname + "&format=json&oflags=bc&contact=" + "ttd-abuse@duck.me.uk",timeout=5.00)
|
||||
if (result.status_code != 200):
|
||||
msgChannel(irc, conn.channel, str("*** *[ADM]* Couldn\'t contact validator to check %s. Status error?" % client.name))
|
||||
return
|
||||
result = json.loads(result.text)
|
||||
except requests.exceptions.RequestException as e:
|
||||
msgChannel(irc, conn.channel, str("*** *[ADM]* Couldn\'t contact validator to check {name}. Timeout?".format(name=client.name)))
|
||||
return
|
||||
|
||||
if (result == None):
|
||||
msgChannel(irc, conn.channel,"*** *[ADM]* Received NONE during checkIP (this should never happen!)")
|
||||
return
|
||||
conn.logger.debug('>>--DEBUG--<< CheckIP result: %s' % str(result))
|
||||
if result['result'] < 0:
|
||||
|
||||
checkedDict[client.hostname] = {'result': result['result'], 'BadIP': result.get('BadIP', 0), 'Country': result['Country'], 'timestamp': datetime.utcnow()}
|
||||
else:
|
||||
checkedDict[client.hostname] = {'result': result['result'], 'message': result.get('message', 'Unknown failure'), 'timestamp': datetime.utcnow()}
|
||||
else:
|
||||
conn.logger.debug('>>--DEBUG--<< Using cached result for IP: %s' % client.hostname)
|
||||
result = checkedDict[client.hostname]
|
||||
|
||||
if float(result['result']) < 0:
|
||||
msgChannel(irc, conn.channel, "*** There was a problem validating {name}. The error was: {error}".format(name=client.name, error=result['message']))
|
||||
elif float(result['result']) == 1:
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT_CLIENT,
|
||||
destType=DestType.CLIENT,
|
||||
clientID=client.id,
|
||||
message='Sorry, connecting from a VPN or proxy is not allowed! Please disable any such software and try again. If you think this is an error, please contact us.')
|
||||
text = '*** {name} was trying to connect from a VPN or proxy in {location}, which is not allowed.'.format(name=client.name, location=result['Country'])
|
||||
command = 'ban %s' % client.id
|
||||
conn.rcon = conn.channel
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
conn.send_packet(AdminRcon, command=command)
|
||||
elif float(result['result']) > 0.95 or result.get('BadIP', 0) == 1:
|
||||
text = str('*** {name} MIGHT BE CONNECTING VIA A PROXY IN {location}. {certainty:.2f} certainty.' + (" Warning: Potential ISP blacklisted address!" if bool(result.get('BadIP', False)) else "")).format(name=client.name, location=result['Country'], certainty=float(result['result'])*100)
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
else:
|
||||
text = '*** {name} is a valid player from {location}.'.format(name=client.name, location=result.get('Country', 'an unknown country'))
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
return
|
||||
|
||||
def moveToSpectators(irc, conn, client, kickCount, kickDict):
|
||||
if client.id in kickDict:
|
||||
kickDict[client.id] += 1
|
||||
else:
|
||||
kickDict[client.id] = 1
|
||||
|
||||
text = '%s: Change your name before joining/starting a company. Use \'!name <new name>\' to do so. (%s OF %s BEFORE KICK)' % (client.name, kickDict[client.id], kickCount)
|
||||
command = 'move %s 255' % client.id
|
||||
conn.rcon = conn.channel
|
||||
conn.send_packet(AdminRcon, command = command)
|
||||
conn.send_packet(AdminChat,
|
||||
action = Action.CHAT,
|
||||
destType = DestType.BROADCAST,
|
||||
clientID = ClientID.SERVER,
|
||||
message = text)
|
||||
conn.send_packet(AdminRcon, command = command)
|
||||
|
||||
if kickDict is not None and kickDict[client.id] >= kickCount:
|
||||
text = 'Kicking %s for reaching name change warning count' % client.name
|
||||
command = 'kick %s' % client.id
|
||||
conn.rcon = conn.channel
|
||||
conn.send_packet(AdminChat,
|
||||
action = Action.CHAT,
|
||||
destType = DestType.BROADCAST,
|
||||
clientID = ClientID.SERVER,
|
||||
message = text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
conn.send_packet(AdminRcon, command = command)
|
||||
|
||||
def playercount(conn):
|
||||
clients = len(conn.clients)
|
||||
if conn.serverinfo.dedicated:
|
||||
clients -= 1 # deduct server-client for dedicated servers
|
||||
players = 0
|
||||
for client in conn.clients.values():
|
||||
if not client.play_as == 255:
|
||||
players += 1
|
||||
spectators = clients - players
|
||||
if clients:
|
||||
text = 'There are currently %d players and %d spectators, '\
|
||||
'making a total of %d clients connected' % (
|
||||
(players, spectators, clients))
|
||||
else:
|
||||
text = 'The server is empty, noone is connected. '\
|
||||
'Feel free to remedy this situation'
|
||||
return text
|
||||
|
||||
def ofsGetsaveExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'Invalid directory in ofs-getsave.py. Please configure it accordingly',
|
||||
0x02 :'Couldn\'t save game to disk',
|
||||
0x03 :'URL did not lead to a valid savegame. Please check the url in your browser',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsStartExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'OpenTTD appears to be running already. Try !apconnect instead',
|
||||
0x02 :'OpenTTD was started succesfully, but openttd.pid could not be updated',
|
||||
0x03 :'Could not start OpenTTD. Check the configuration of ofs-start.py',
|
||||
0x04 :'Started OpenTTD, but couldn\'t read a valid pid from the output. Likely something went wrong',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsSvnToBinExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'Copying the new executable to the server directory did not succeed',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsSvnUpdateExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'Source directory does not seem to exist. Please check ofs-svnupdate.py configuration',
|
||||
0x02 :'Invalid branch selected in ofs-svnupdate.py\'s configuration. Please use nightlies/trunk, stable or testing',
|
||||
0x03 :'Something went wrong executing make or svn. Please run ofs-svnupdate.py manually and see what goes wrong',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsTransferSaveExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'File already exists, not transferring savegame',
|
||||
0x02 :'Missing either game ID or savegame, or possibly both',
|
||||
0x03 :'SSH configuration invalid. Please review ofs-transfersave.py\'s configuration',
|
||||
0x04 :'Couldn\'t find file, please specify a valid savegame',
|
||||
0x05 :'Failed to trasfer the savegame. Please run ofs-transfersave manually to see what causes this',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def refreshConnection(connections, registeredConnections, conn):
|
||||
try:
|
||||
del registeredConnections[conn.filenumber]
|
||||
except KeyError:
|
||||
pass
|
||||
newconn = conn.copy()
|
||||
connections[conn.channel] = newconn
|
||||
return newconn
|
||||
|
||||
def vehicleCount(companies):
|
||||
rail = road = water = air = 0
|
||||
for company in companies.values():
|
||||
if not company.id == 255:
|
||||
rail += company.vehicles.train
|
||||
road += (company.vehicles.lorry + company.vehicles.bus)
|
||||
water += company.vehicles.ship
|
||||
air += company.vehicles.plane
|
||||
return (rail, road, water, air)
|
||||
|
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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) year 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 Lesser General
|
||||
Public License instead of this License.
|
117
suds3/README.md
117
suds3/README.md
|
@ -1,117 +0,0 @@
|
|||
# Suds from /r/openttd
|
||||
### A Supybot Plugin for communicating with OpenTTD servers via the AdminPort interface
|
||||
____
|
||||
|
||||
This plugin is released under the GPL, a copy of which has been included in COPYING.txt
|
||||
____
|
||||
|
||||
#### Prerequisites
|
||||
* working OpenTTD server (optionally OFS installed and configured)
|
||||
* Supybot set up in a channel
|
||||
* libottdadmin2 by Xaroth installed
|
||||
|
||||
Supybot comes with its own installation instructions. Those and its user manual
|
||||
can be found here: http://sourceforge.net/projects/supybot/
|
||||
|
||||
OFS (Openttd File Scripts) can be obtained here: http://dev.openttdcoop.org/projects/ofs
|
||||
It simply needs to be copied to a directory on the same user@host as that
|
||||
OpenTTD server, and configured. See the included readme.txt for details. If the
|
||||
server is located on a different user@host from the bot, you will need to give
|
||||
the user running the bot password-less ssh access to the user@host. This allows
|
||||
the bot to eg download a savegame to the server.
|
||||
|
||||
###### Installing libottdadmin2:
|
||||
First go to https://github.com/Xaroth/libottdadmin2 and either download the zip
|
||||
or git clone. Now there are 2 ways you can install this lib:
|
||||
|
||||
The first one is the easiest one, run `python2 setup.py install` from the
|
||||
libottdadmin2 dir. This will install the lib systemwide and make it available
|
||||
to any other python programs that may need it. You may need sudo access
|
||||
depending on the system setup though.
|
||||
|
||||
The other way is to copy the libottdadmin2 dir into the Soap plugin directory.
|
||||
Copied right client.py should be found at this path:
|
||||
`<PathToPlugins>/Soap/libottdadmin2/client.py`
|
||||
This will give the same functionality, but only for the Soap plugin. On the
|
||||
upside, no sudo access required.
|
||||
|
||||
____
|
||||
|
||||
#### Installation
|
||||
|
||||
To install Soap, simply copy the Soap directory into the bots plugin directory,
|
||||
and load the plugin once the bot is running.
|
||||
#### Configuration
|
||||
|
||||
Configuration is handled via supybot's config command. First thing you want to
|
||||
configure is the default settings. Soap can handle multiple game-servers, but
|
||||
is bound to 1 server per irc-channel.
|
||||
|
||||
Correct format for config would be `config plugins.Soap.<setting> <value>` - for example, `config plugins.Soap.host 127.0.0.1`
|
||||
|
||||
This will set the default for any new server to 127.0.0.1
|
||||
|
||||
To change a setting for one server only, you want to specify the channel: `config channel [#yourchan] plugins.Soap.<setting> <value>`
|
||||
|
||||
#yourchannel is optional when used in the channel (it will use the current
|
||||
channel), but required when used in queries. You'll want to use the latter method
|
||||
for setting the password. Example: `config channel #mychannel supybot.plugins.Soap.host 127.0.0.1` can be used anywhere the bot is, whilst `config channel plugins.Soap.host 127.0.0.1` will change the host for channel the command was issued in.
|
||||
|
||||
Finally, you want to activate the channels by configuring the list of
|
||||
channels. This is a global value, so theres only one variation: `config plugins.Soap.channels #mychannel #myotherchannel ...`, which will enable below commands for servers tied to those channels. Changing this
|
||||
setting will require reloading the plugin so that it can set up all the connections correctly.
|
||||
|
||||
If you didn't specify any settings for a channel, it will pick the default setting instead.
|
||||
This also means, that if you want one setting to apply to all the servers (eg you run
|
||||
all on a non-standard adminport), simply change the option as if it were a global
|
||||
setting.
|
||||
|
||||
For a description of the individual variables, see config.py.
|
||||
|
||||
## Command List
|
||||
|
||||
Op/Trusted-only commands:
|
||||
* `apconnect` - connects to the openttd server
|
||||
* `apdisconnect` - disconnects from same
|
||||
* `pause` - manually pauses the game
|
||||
* `unpause` - manually unpauses the game (sets min_active_clients to 0)
|
||||
* `auto` - turns on autopause, and re-sets min_active_clients to theconfigured amount
|
||||
* `rcon` - sends an rcon command to the server
|
||||
* `players` - lists the clients connected to the server
|
||||
* `content` - updates the downloaded content from bananas
|
||||
* `contentupdate` - performs 'content update'. use this before using the 'content' command
|
||||
* `rescan` - rescans the content_download directory for new files. (May cause users to get disconnected)
|
||||
* `save` - saves the game to game.sav
|
||||
* `transfer` - transfers savegame to a web-accessible directory (usage: !transfer number savegame)
|
||||
|
||||
Commands requiring op/trusted and OFS installed
|
||||
* `getsave` - download savegame from url
|
||||
* `start` - starts OpenTTD dedicated server
|
||||
* `update` - updates the OpenTTD server and (re)starts it
|
||||
|
||||
Publicly available commands
|
||||
* `playercount` - shows how many people are playing
|
||||
* `companies` - lists companies
|
||||
* `date` - returns the ingame date
|
||||
* `ding` - should be ping, but that command was taken. Dings the server
|
||||
* `help` - links to http://wiki.openttdcoop.org/Soap
|
||||
* `info` - shows some basic info about the server
|
||||
* `ip` - replies with the address needed to join the server as a player
|
||||
* `password` - shows the current password needed to join the server
|
||||
* `revision` - shows current revision of the OpenTTD server
|
||||
* `vehicles` - totals each vehicle type in the game
|
||||
|
||||
These commands can also be called with channel or serverID as parameter. This can
|
||||
be handy when you want to command a server from a different channel or from
|
||||
private message.
|
||||
|
||||
There are also 3 ingame commands:
|
||||
* `!admin` - sends a message to irc requesting admins look at the server
|
||||
* `!nick <newnick>` - will change the ingame nick of the caller
|
||||
* `!rules` - replies with an url pointing to the rules for playing
|
||||
|
||||
|
||||
### Credit where credit is due
|
||||
* Taede Werkhoven: For writing SOAP, which this plugin is derived from
|
||||
* Xaroth: For writing libottdadmin2
|
||||
* Dihedral: generated passwords.txt from OpenTTD source
|
|
@ -1,66 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
"""
|
||||
lets the bot communicate with openttd via its adminport, and to control same
|
||||
"""
|
||||
|
||||
import supybot
|
||||
import supybot.world as world
|
||||
import importlib
|
||||
|
||||
# Use this for the version of this plugin. You may wish to put a CVS keyword
|
||||
# in here if you're keeping the plugin in CVS or some similar system.
|
||||
__version__ = ""
|
||||
|
||||
# XXX Replace this with an appropriate author or supybot.Author instance.
|
||||
__author__ = supybot.Author('Taede Werkhoven', 'TWerkhoven', 't.werkhoven@turbulent-t.com')
|
||||
__maintainer__ = getattr(supybot.authors, 'oddluck',
|
||||
supybot.Author('oddluck', 'oddluck', 'oddluck@riseup.net'))
|
||||
|
||||
# This is a dictionary mapping supybot.Author instances to lists of
|
||||
# contributions.
|
||||
__contributors__ = {}
|
||||
|
||||
# This is a url where the most recent plugin package can be downloaded.
|
||||
__url__ = 'https://github.com/oddluck/limnoria-plugins/'
|
||||
|
||||
from . import config
|
||||
from . import enums
|
||||
from . import soaputils
|
||||
from . import soapclient
|
||||
import libottdadmin2
|
||||
from . import plugin
|
||||
importlib.reload(config)
|
||||
importlib.reload(enums)
|
||||
importlib.reload(soaputils)
|
||||
importlib.reload(soapclient)
|
||||
importlib.reload(libottdadmin2)
|
||||
importlib.reload(plugin)
|
||||
|
||||
# In case we're being reloaded.
|
||||
# Add more reloads here if you add third-party modules and want them to be
|
||||
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
||||
|
||||
if world.testing:
|
||||
import test
|
||||
|
||||
Class = plugin.Class
|
||||
configure = config.configure
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
138
suds3/config.py
138
suds3/config.py
|
@ -1,138 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
import re
|
||||
|
||||
class SemicolonSeparatedListOfStrings(registry.SeparatedListOf):
|
||||
Value = registry.String
|
||||
def splitter(self, s):
|
||||
return re.split(r'\s*;\s*', s)
|
||||
joiner = '; '.join
|
||||
|
||||
|
||||
def configure(advanced):
|
||||
# This will be called by supybot to configure this module. advanced is
|
||||
# a bool that specifies whether the user identified himself as an advanced
|
||||
# user or not. You should effect your configuration by manipulating the
|
||||
# registry as appropriate.
|
||||
from supybot.questions import expect, anything, something, yn
|
||||
conf.registerPlugin('suds', True)
|
||||
|
||||
|
||||
Suds = conf.registerPlugin('suds')
|
||||
# This is where your configuration variables (if any) should go. For example:
|
||||
# conf.registerGlobalValue(Suds, 'someConfigVariableName',
|
||||
# registry.Boolean(False, """Help for someConfigVariableName."""))
|
||||
|
||||
|
||||
# General configuration settings
|
||||
conf.registerGlobalValue(Suds, 'channels',
|
||||
registry.SpaceSeparatedListOfStrings('', """ The channels you wish to use
|
||||
for OpenTTD communication """))
|
||||
conf.registerGlobalValue(Suds, 'logdir',
|
||||
registry.String('None', """ Logging directory. This is where logfiles are
|
||||
saved to. It will rotate logs when a new game starts, and back up the old
|
||||
log. A maximum of 2 logs are backed up. To disable logging, set this to an
|
||||
invalid path or 'None' """))
|
||||
conf.registerGlobalValue(Suds, 'logHistory',
|
||||
registry.Integer(2, """ Amount of logfiles to keep. This does not include
|
||||
the current logfile. A value of 2 will keep the current logfile, and the 2
|
||||
preceding ones as .log.1 and .log.2."""))
|
||||
|
||||
# OpenTTD server configuration
|
||||
conf.registerChannelValue(Suds, 'serverID',
|
||||
registry.String('default', """ Optional hort name for the server, used for
|
||||
issuing commands via query. no spaces allowed. Should be unique to each
|
||||
server when managing multiple game-servers """))
|
||||
conf.registerChannelValue(Suds, 'host',
|
||||
registry.String('127.0.0.1', """ The hostname or IP-adress of the OpenTTD
|
||||
server you wish the bot to connect to """))
|
||||
conf.registerChannelValue(Suds, 'port',
|
||||
registry.Integer(3977, """ The port of the server's adminport """))
|
||||
conf.registerChannelValue(Suds, 'password',
|
||||
registry.String('password', """ The password as set in openttd.cfg """))
|
||||
conf.registerChannelValue(Suds, 'publicAddress',
|
||||
registry.String('openttd.example.org', """ Address players use to connect
|
||||
to the server """))
|
||||
|
||||
# File-related settings
|
||||
conf.registerChannelValue(Suds, 'ofslocation',
|
||||
registry.String('/home/openttdserver/', """ Location of OpenTTD File Scripts
|
||||
(OFS). This can either be a local directory (/path/to/ofs/{OFS}) or in the form of
|
||||
'ssh -p23 user@host:/path/to/ofs/{OFS}'. In the latter case, make sure to set up
|
||||
the bot-user to have password-less login to the machine with ofs/openttd. Put
|
||||
{OFS} wher the actual ofs-command should go. """))
|
||||
|
||||
# Miscellanious server-specific settings
|
||||
conf.registerChannelValue(Suds, 'autoConnect',
|
||||
registry.Boolean(False, """ Setting this to True will cause the bot to
|
||||
attempt to connect to OpenTTD automatically """))
|
||||
conf.registerChannelValue(Suds, 'allowOps',
|
||||
registry.Boolean(True, """ Setting this to True will allow any op as well
|
||||
as trusted user in the channel to execute soap commands . Setting this to
|
||||
False only allows trusted users to do so """ ))
|
||||
conf.registerChannelValue(Suds, 'minPlayers',
|
||||
registry.Integer(0, """ The defalt minimum number of players for the server
|
||||
to unpause itself. 0 means game never pauses unless manually paused """))
|
||||
conf.registerChannelValue(Suds, 'checkClientVPN',
|
||||
registry.Boolean(False, """ True means players will have their IP checked for
|
||||
known VPN or other such ban evasion techniques, and kicked if they are using them."""))
|
||||
conf.registerGlobalValue(Suds, 'checkClientVPNWhitelist',
|
||||
SemicolonSeparatedListOfStrings('', """If checkClientVPN is enabled, you can disable checking certain IPs here. Semicolon delimited."""))
|
||||
conf.registerGlobalValue(Suds, 'nameBlacklist',
|
||||
SemicolonSeparatedListOfStrings('', """List of player names to autokick. Semicolon delimited."""))
|
||||
conf.registerChannelValue(Suds, 'playAsPlayer',
|
||||
registry.Boolean(True, """ True means players can play with Player as their
|
||||
name. False will get them moved to spectators any time they try to join a
|
||||
company, and eventually kicked """))
|
||||
conf.registerChannelValue(Suds, 'playerKickCount',
|
||||
registry.Integer(3, """ The number of times a player can attempt to join
|
||||
a company before they are automatically kicked. Setting to 0 will kick
|
||||
on the first infraction. """))
|
||||
conf.registerChannelValue(Suds, 'passwordInterval',
|
||||
registry.Integer(0, """ Interval in seconds between soap changing the
|
||||
password clients use to join the server. Picks a random line from the
|
||||
included passwords.txt. If you don't want your server to have random
|
||||
passwords, leave this set at 0. People can use the password command to find
|
||||
the current password """))
|
||||
conf.registerChannelValue(Suds, 'welcomeMessage',
|
||||
SemicolonSeparatedListOfStrings('', """ Welcome message to be sent to
|
||||
players when they connect. Separate lines with semicolons. to insert (for
|
||||
instance) the client name, put {clientname} in the string, including the {}.
|
||||
Valid replacements are: {clientname} {servername} and {serverversion}. Set
|
||||
this to 'None' to disable on-join welcome messages """))
|
||||
conf.registerChannelValue(Suds, 'defaultSettings',
|
||||
registry.String('', """ This should be an absolute path pointing to a textfile
|
||||
containing one command per line. This file is read by the setdef command, and
|
||||
all commands are executed """))
|
||||
|
||||
# various URL's
|
||||
conf.registerChannelValue(Suds, 'downloadUrl',
|
||||
registry.String('None', """ Custom download url. Use only if using a custom version
|
||||
that cannot be obtained from openttd.org. Soap will automatically generate url's
|
||||
for openttd stable and nightly versions."""))
|
||||
conf.registerChannelValue(Suds, 'rulesUrl',
|
||||
registry.String('None', """ Url where the rules for the server can be found.
|
||||
Set to 'None' to disable the ingame and irc !rules commands. """))
|
||||
conf.registerChannelValue(Suds, 'saveUrl',
|
||||
registry.String('None', """ Url where savegames will be available after
|
||||
using the transfer command. enter the full url, including the filename. Use
|
||||
{ID} where the game number goes"""))
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
|
@ -1,43 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
from libottdadmin2.enums import EnumHelper
|
||||
|
||||
class ConnectionState(EnumHelper):
|
||||
DISCONNECTED = 0x00
|
||||
CONNECTING = 0x01
|
||||
AUTHENTICATING = 0x02
|
||||
CONNECTED = 0x03
|
||||
DISCONNECTING = 0x04
|
||||
SHUTDOWN = 0x05
|
||||
|
||||
class PauseState(EnumHelper):
|
||||
UNPAUSED = 0x00 # Unpaused
|
||||
PAUSED_NORMAL = 0x01 # Paused manually
|
||||
PAUSED_SAVELOAD = 0x02 # Paused for saving/loading
|
||||
PAUSED_JOIN = 0x04 # Pause on join
|
||||
PAUSED_ERROR = 0x08 # Pause because of a (critical) error
|
||||
PAUSED_ACTIVE_CLIENTS = 0x10 # Pause for 'min_active_clients'
|
||||
PAUSED_GAMESCRIPT = 0x20 # Paused by game script
|
||||
|
||||
class RconStatus(EnumHelper):
|
||||
IDLE = 0x00 # We are not processing any rcon commands
|
||||
ACTIVE = 0x01 # We are awayting rcon results
|
||||
CHANNEL = 0x02 # Automatic rcon command has output for the channel
|
||||
SHUTDOWNSAVED = 0x03 # Game has been saved by the shutdown command, no output
|
||||
UPDATESAVED = 0x04 # Game has been saved prior to shutting down for update, no output
|
||||
RESTARTSAVED = 0x05 # Game has been saved prior to restarting, no output
|
1107
suds3/passwords.txt
1107
suds3/passwords.txt
File diff suppressed because it is too large
Load Diff
1728
suds3/plugin.py
1728
suds3/plugin.py
File diff suppressed because it is too large
Load Diff
|
@ -1,220 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
import logging
|
||||
import queue
|
||||
|
||||
from libottdadmin2.trackingclient import TrackingAdminClient
|
||||
from libottdadmin2.event import Event
|
||||
from libottdadmin2.enums import UpdateType, UpdateFrequency
|
||||
|
||||
from .enums import RconStatus, ConnectionState
|
||||
|
||||
class SoapEvents(object):
|
||||
def __init__(self):
|
||||
self.connected = Event()
|
||||
self.disconnected = Event()
|
||||
|
||||
self.shutdown = Event()
|
||||
self.new_game = Event()
|
||||
|
||||
self.new_map = Event()
|
||||
# self.protocol = Event()
|
||||
|
||||
# self.datechanged = Event()
|
||||
|
||||
# self.clientinfo = Event()
|
||||
self.clientjoin = Event()
|
||||
self.clientupdate = Event()
|
||||
self.clientquit = Event()
|
||||
|
||||
# self.companyinfo = Event()
|
||||
# self.companynew = Event()
|
||||
# self.companyupdate = Event()
|
||||
# self.companyremove = Event()
|
||||
# self.companystats = Event()
|
||||
# self.companyeconomy = Event()
|
||||
|
||||
self.chat = Event()
|
||||
self.rcon = Event()
|
||||
self.rconend = Event()
|
||||
self.console = Event()
|
||||
self.cmdlogging = Event()
|
||||
|
||||
self.pong = Event()
|
||||
|
||||
class SoapClient(TrackingAdminClient):
|
||||
|
||||
|
||||
|
||||
# Initialization & miscellanious functions
|
||||
|
||||
def __init__(self, channel, serverid, events = None):
|
||||
super(SoapClient, self).__init__(events)
|
||||
self.channel = channel
|
||||
self.ID = serverid
|
||||
self.soapEvents = SoapEvents()
|
||||
self._attachEvents()
|
||||
self.logger = logging.getLogger('Soap-%s' % self.ID)
|
||||
self.logger.setLevel(logging.INFO)
|
||||
|
||||
self.rconCommands = queue.Queue()
|
||||
self.rconNick = None
|
||||
self.rconResults = {}
|
||||
self.rconState = RconStatus.IDLE
|
||||
|
||||
self.connectionstate = ConnectionState.DISCONNECTED
|
||||
self.registered = False
|
||||
self.filenumber = None
|
||||
|
||||
self.clientPassword = None
|
||||
|
||||
def _attachEvents(self):
|
||||
self.events.connected += self._rcvConnected
|
||||
self.events.disconnected += self._rcvDisconnected
|
||||
|
||||
self.events.shutdown += self._rcvShutdown
|
||||
self.events.new_game += self._rcvNewGame
|
||||
|
||||
self.events.new_map += self._rcvNewMap
|
||||
|
||||
self.events.clientjoin += self._rcvClientJoin
|
||||
self.events.clientupdate += self._rcvClientUpdate
|
||||
self.events.clientquit += self._rcvClientQuit
|
||||
|
||||
self.events.chat += self._rcvChat
|
||||
self.events.rcon += self._rcvRcon
|
||||
self.events.rconend += self._rcvRconEnd
|
||||
self.events.console += self._rcvConsole
|
||||
self.events.cmdlogging += self._rcvCmdLogging
|
||||
|
||||
self.events.pong += self._rcvPong
|
||||
|
||||
def copy(self):
|
||||
obj = SoapClient(self._channel, self._ID, self.events)
|
||||
for prop in self._settable_args:
|
||||
setattr(obj, prop, getattr(self, prop, None))
|
||||
return obj
|
||||
|
||||
|
||||
|
||||
# Insert connection info into parameters
|
||||
|
||||
def _rcvConnected(self):
|
||||
self.registered = True
|
||||
self.soapEvents.connected(self.channel)
|
||||
|
||||
def _rcvDisconnected(self, canRetry):
|
||||
self.registered = False
|
||||
self.soapEvents.disconnected(self.channel, canRetry)
|
||||
|
||||
def _rcvShutdown(self):
|
||||
self.soapEvents.shutdown(self.channel)
|
||||
|
||||
def _rcvNewGame(self):
|
||||
self.soapEvents.new_game(self.channel)
|
||||
|
||||
def _rcvNewMap(self, mapinfo, serverinfo):
|
||||
self.soapEvents.new_map(self.channel, mapinfo, serverinfo)
|
||||
|
||||
def _rcvClientJoin(self, client):
|
||||
self.soapEvents.clientjoin(self.channel, client)
|
||||
|
||||
def _rcvClientUpdate(self, old, client, changed):
|
||||
self.soapEvents.clientupdate(self.channel, old, client, changed)
|
||||
|
||||
def _rcvClientQuit(self, client, errorcode):
|
||||
self.soapEvents.clientquit(self.channel, client, errorcode)
|
||||
|
||||
def _rcvChat(self, **kwargs):
|
||||
data = dict(list(kwargs.items()))
|
||||
data['connChan'] = self.channel
|
||||
self.soapEvents.chat(**data)
|
||||
|
||||
def _rcvRcon(self, result, colour):
|
||||
self.soapEvents.rcon(self.channel, result, colour)
|
||||
|
||||
def _rcvRconEnd(self, command):
|
||||
self.soapEvents.rconend(self.channel, command)
|
||||
|
||||
def _rcvConsole(self, message, origin):
|
||||
self.soapEvents.console(self.channel, origin, message)
|
||||
|
||||
def _rcvCmdLogging(self, **kwargs):
|
||||
data = dict(list(kwargs.items()))
|
||||
data['connChan'] = self.channel
|
||||
self.soapEvents.cmdlogging(**data)
|
||||
|
||||
def _rcvPong(self, start, end, delta):
|
||||
self.soapEvents.pong(self.channel, start, end, delta)
|
||||
|
||||
|
||||
|
||||
# Store some extra info
|
||||
|
||||
_settable_args = TrackingAdminClient._settable_args + ['irc', 'ID', 'channel', 'debugLog']
|
||||
_irc = None
|
||||
_ID = 'Default'
|
||||
_channel = None
|
||||
_debugLog = False
|
||||
|
||||
@property
|
||||
def channel(self):
|
||||
return self._channel
|
||||
|
||||
@channel.setter
|
||||
def channel(self, value):
|
||||
self._channel = value.lower()
|
||||
|
||||
@property
|
||||
def irc(self):
|
||||
return self._irc
|
||||
|
||||
@irc.setter
|
||||
def irc(self, value):
|
||||
self._irc = value
|
||||
|
||||
@property
|
||||
def ID(self):
|
||||
return self._ID
|
||||
|
||||
@ID.setter
|
||||
def ID(self, value):
|
||||
self._ID = value.lower()
|
||||
|
||||
@property
|
||||
def debugLog(self):
|
||||
return self._debugLog
|
||||
|
||||
@debugLog.setter
|
||||
def debugLog(self, value):
|
||||
self._debugLog = value
|
||||
if self._debugLog:
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
else:
|
||||
self.logger.setLevel(logging.INFO)
|
||||
|
||||
update_types = [
|
||||
(UpdateType.CLIENT_INFO, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.COMPANY_INFO, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.COMPANY_ECONOMY, UpdateFrequency.WEEKLY),
|
||||
(UpdateType.COMPANY_STATS, UpdateFrequency.WEEKLY),
|
||||
(UpdateType.CHAT, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.CONSOLE, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.LOGGING, UpdateFrequency.AUTOMATIC),
|
||||
(UpdateType.DATE, UpdateFrequency.DAILY),
|
||||
]
|
|
@ -1,391 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
###
|
||||
# This file is part of Soap.
|
||||
#
|
||||
# Soap 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, version 2.
|
||||
#
|
||||
# Soap 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 Soap. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.ircdb as ircdb
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import supybot.ircutils as ircutils
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os.path
|
||||
import re
|
||||
import urllib.request, urllib.error, urllib.parse
|
||||
import requests
|
||||
import sys
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from .enums import *
|
||||
from libottdadmin2.enums import Colour, Action, DestType, ClientID
|
||||
from libottdadmin2.packets.admin import AdminRcon, AdminChat
|
||||
from libottdadmin2.trackingclient import MappingObject
|
||||
|
||||
class RconResults(MappingObject):
|
||||
_mapping = [
|
||||
('irc', 'irc'),
|
||||
('command', 'command'),
|
||||
('succestext', 'succestext'),
|
||||
('results', 'results'),
|
||||
]
|
||||
|
||||
def checkPermission(irc, msg, channel, allowOps):
|
||||
capable = ircdb.checkCapability(msg.prefix, 'trusted')
|
||||
if capable:
|
||||
return True
|
||||
else:
|
||||
opped = msg.nick in irc.state.channels[channel].ops
|
||||
if opped and allowOps:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def disconnect(conn, forced):
|
||||
if forced:
|
||||
conn.force_disconnect()
|
||||
else:
|
||||
conn.disconnect()
|
||||
|
||||
def generateDownloadUrl(irc, version, osType = None):
|
||||
stable = '\d\.\d\.\d'
|
||||
testing = '\d\.\d\.\d-rc\d'
|
||||
trunk = 'r\d{5}'
|
||||
|
||||
if not osType:
|
||||
url = 'http://www.openttd.org/en/'
|
||||
if re.match(stable, version) or re.match(testing, version):
|
||||
url += 'download-stable/%s' % version
|
||||
elif re.match(trunk, version):
|
||||
url += 'download-trunk/%s' % version
|
||||
else:
|
||||
url = None
|
||||
else:
|
||||
url = 'http://binaries.openttd.org/'
|
||||
if re.match(stable, version):
|
||||
url += 'releases/%s/openttd-%s-' % (version, version)
|
||||
elif re.match(trunk, version):
|
||||
url += 'nightlies/trunk/%s/openttd-trunk-%s-' % (version, version)
|
||||
else:
|
||||
url = None
|
||||
if url:
|
||||
if osType.startswith('lin'):
|
||||
url += 'linux-generic-'
|
||||
if osType == 'lin':
|
||||
url += 'i686.tar.xz'
|
||||
elif osType == 'lin64':
|
||||
url += 'amd64.tar.xz'
|
||||
else:
|
||||
url = None
|
||||
elif osType == 'osx':
|
||||
url += 'macosx-universal.zip'
|
||||
elif osType == 'source':
|
||||
url += 'source.tar.xz'
|
||||
elif osType.startswith('win'):
|
||||
url += 'windows-%s.zip' % osType
|
||||
else:
|
||||
url = None
|
||||
return url
|
||||
|
||||
def getColourNameFromNumber(number):
|
||||
colours = {
|
||||
Colour.COLOUR_DARK_BLUE : 'Dark Blue',
|
||||
Colour.COLOUR_PALE_GREEN : 'Pale Green',
|
||||
Colour.COLOUR_PINK : 'Pink',
|
||||
Colour.COLOUR_YELLOW : 'Yellow',
|
||||
Colour.COLOUR_RED : 'Red',
|
||||
Colour.COLOUR_LIGHT_BLUE : 'Light Blue',
|
||||
Colour.COLOUR_GREEN : 'Green',
|
||||
Colour.COLOUR_DARK_GREEN : 'Dark Green',
|
||||
Colour.COLOUR_BLUE : 'Blue',
|
||||
Colour.COLOUR_CREAM : 'Cream',
|
||||
Colour.COLOUR_MAUVE : 'Mauve',
|
||||
Colour.COLOUR_PURPLE : 'Purple',
|
||||
Colour.COLOUR_ORANGE : 'Orange',
|
||||
Colour.COLOUR_BROWN : 'Brown',
|
||||
Colour.COLOUR_GREY : 'Grey',
|
||||
Colour.COLOUR_WHITE : 'White',
|
||||
}
|
||||
colourName = colours.get(number, number)
|
||||
return colourName
|
||||
|
||||
def getQuitReasonFromNumber(number):
|
||||
reasons = {
|
||||
0x00 :'general error',
|
||||
0x01 :'desync error',
|
||||
0x02 :'could not load map',
|
||||
0x03 :'connection lost',
|
||||
0x04 :'protocol error',
|
||||
0x05 :'NewGRF mismatch',
|
||||
0x06 :'not authorized',
|
||||
0x07 :'received invalid or unexpected packet',
|
||||
0x08 :'wrong revision',
|
||||
0x09 :'name already in use',
|
||||
0x0A :'wrong password',
|
||||
0x0B :'wrong company in DoCommand',
|
||||
0x0C :'kicked by server',
|
||||
0x0D :'was trying to use a cheat',
|
||||
0x0E :'server full',
|
||||
0x0F :'was sending too many commands',
|
||||
0x10 :'received no password in time',
|
||||
0x11 :'general timeout',
|
||||
0x12 :'downloading map took too long',
|
||||
0x13 :'processing map took too long',
|
||||
}
|
||||
reasonText = reasons.get(number, number)
|
||||
return reasonText
|
||||
|
||||
def getConnection(connections, channels, source, serverID = None):
|
||||
conn = None
|
||||
|
||||
if not serverID:
|
||||
if ircutils.isChannel(source) and source.lower() in channels:
|
||||
conn = connections.get(source)
|
||||
else:
|
||||
if ircutils.isChannel(serverID):
|
||||
conn = connections.get(serverID)
|
||||
|
||||
serverID = serverID and serverID.lower() or 'default'
|
||||
|
||||
if not conn:
|
||||
for c in connections.values():
|
||||
if c.ID == serverID:
|
||||
conn = c
|
||||
|
||||
return conn
|
||||
|
||||
def getConnectionID(conn):
|
||||
if conn.ID == 'default':
|
||||
return conn.channel
|
||||
else:
|
||||
return conn.ID
|
||||
|
||||
def initLogger(conn, logdir, history):
|
||||
if os.path.isdir(logdir):
|
||||
if not len(conn.logger.handlers):
|
||||
logfile = os.path.join(logdir, '%s.log' % conn.ID)
|
||||
logformat = logging.Formatter('%(asctime)s %(message)s')
|
||||
handler = logging.handlers.RotatingFileHandler(logfile, backupCount = history)
|
||||
handler.setFormatter(logformat)
|
||||
conn.logger.addHandler(handler)
|
||||
|
||||
def logEvent(logger, message):
|
||||
try:
|
||||
logger.info(message)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def msgChannel(irc, channel, msg):
|
||||
if channel in irc.state.channels or irc.isNick(channel):
|
||||
irc.queueMsg(ircmsgs.privmsg(channel, msg))
|
||||
|
||||
def checkIP(irc, conn, client, whitelist, checkedDict):
|
||||
|
||||
if client.hostname in whitelist:
|
||||
text = '*** {name} is a whitelisted player, and will not be checked.'.format(name=client.name)
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
return
|
||||
result = None
|
||||
|
||||
# First let's garbage collect
|
||||
# learner's note: you can't just do iteritems() into a del because you'll get a RuntimeError exception when
|
||||
# the dictionary changes size during the loop
|
||||
cutoff = datetime.utcnow() - timedelta(days=1)
|
||||
checkedDict = { k:v for k,v in checkedDict.items() if v.get('timestamp') < cutoff }
|
||||
|
||||
if client.hostname not in checkedDict \
|
||||
or not checkedDict.get(client.hostname, {}).get('message', False):
|
||||
try:
|
||||
result = requests.get("http://check.getipintel.net/check.php?ip=" + client.hostname + "&format=json&oflags=bc&contact=" + "ttd-abuse@duck.me.uk",timeout=5.00)
|
||||
if (result.status_code != 200):
|
||||
msgChannel(irc, conn.channel, str("*** *[ADM]* Couldn\'t contact validator to check %s. Status error?" % client.name))
|
||||
return
|
||||
result = json.loads(result.text)
|
||||
except requests.exceptions.RequestException as e:
|
||||
msgChannel(irc, conn.channel, str("*** *[ADM]* Couldn\'t contact validator to check {name}. Timeout?".format(name=client.name)))
|
||||
return
|
||||
|
||||
if (result == None):
|
||||
msgChannel(irc, conn.channel,"*** *[ADM]* Received NONE during checkIP (this should never happen!)")
|
||||
return
|
||||
conn.logger.debug('>>--DEBUG--<< CheckIP result: %s' % str(result))
|
||||
if result['result'] < 0:
|
||||
|
||||
checkedDict[client.hostname] = {'result': result['result'], 'BadIP': result.get('BadIP', 0), 'Country': result['Country'], 'timestamp': datetime.utcnow()}
|
||||
else:
|
||||
checkedDict[client.hostname] = {'result': result['result'], 'message': result.get('message', 'Unknown failure'), 'timestamp': datetime.utcnow()}
|
||||
else:
|
||||
conn.logger.debug('>>--DEBUG--<< Using cached result for IP: %s' % client.hostname)
|
||||
result = checkedDict[client.hostname]
|
||||
|
||||
if float(result['result']) < 0:
|
||||
msgChannel(irc, conn.channel, "*** There was a problem validating {name}. The error was: {error}".format(name=client.name, error=result['message']))
|
||||
elif float(result['result']) == 1:
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT_CLIENT,
|
||||
destType=DestType.CLIENT,
|
||||
clientID=client.id,
|
||||
message='Sorry, connecting from a VPN or proxy is not allowed! Please disable any such software and try again. If you think this is an error, please contact us.')
|
||||
text = '*** {name} was trying to connect from a VPN or proxy in {location}, which is not allowed.'.format(name=client.name, location=result['Country'])
|
||||
command = 'ban %s' % client.id
|
||||
conn.rcon = conn.channel
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
conn.send_packet(AdminRcon, command=command)
|
||||
elif float(result['result']) > 0.95 or result.get('BadIP', 0) == 1:
|
||||
text = str('*** {name} MIGHT BE CONNECTING VIA A PROXY IN {location}. {certainty:.2f} certainty.' + (" Warning: Potential ISP blacklisted address!" if bool(result.get('BadIP', False)) else "")).format(name=client.name, location=result['Country'], certainty=float(result['result'])*100)
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
else:
|
||||
text = '*** {name} is a valid player from {location}.'.format(name=client.name, location=result.get('Country', 'an unknown country'))
|
||||
conn.send_packet(AdminChat,
|
||||
action=Action.CHAT,
|
||||
destType=DestType.BROADCAST,
|
||||
clientID=ClientID.SERVER,
|
||||
message=text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
return
|
||||
|
||||
def moveToSpectators(irc, conn, client, kickCount, kickDict):
|
||||
if client.id in kickDict:
|
||||
kickDict[client.id] += 1
|
||||
else:
|
||||
kickDict[client.id] = 1
|
||||
|
||||
text = '%s: Change your name before joining/starting a company. Use \'!name <new name>\' to do so. (%s OF %s BEFORE KICK)' % (client.name, kickDict[client.id], kickCount)
|
||||
command = 'move %s 255' % client.id
|
||||
conn.rcon = conn.channel
|
||||
conn.send_packet(AdminRcon, command = command)
|
||||
conn.send_packet(AdminChat,
|
||||
action = Action.CHAT,
|
||||
destType = DestType.BROADCAST,
|
||||
clientID = ClientID.SERVER,
|
||||
message = text)
|
||||
conn.send_packet(AdminRcon, command = command)
|
||||
|
||||
if kickDict is not None and kickDict[client.id] >= kickCount:
|
||||
text = 'Kicking %s for reaching name change warning count' % client.name
|
||||
command = 'kick %s' % client.id
|
||||
conn.rcon = conn.channel
|
||||
conn.send_packet(AdminChat,
|
||||
action = Action.CHAT,
|
||||
destType = DestType.BROADCAST,
|
||||
clientID = ClientID.SERVER,
|
||||
message = text)
|
||||
msgChannel(irc, conn.channel, text)
|
||||
conn.send_packet(AdminRcon, command = command)
|
||||
|
||||
def playercount(conn):
|
||||
clients = len(conn.clients)
|
||||
if conn.serverinfo.dedicated:
|
||||
clients -= 1 # deduct server-client for dedicated servers
|
||||
players = 0
|
||||
for client in list(conn.clients.values()):
|
||||
if not client.play_as == 255:
|
||||
players += 1
|
||||
spectators = clients - players
|
||||
if clients:
|
||||
text = 'There are currently %d players and %d spectators, '\
|
||||
'making a total of %d clients connected' % (
|
||||
(players, spectators, clients))
|
||||
else:
|
||||
text = 'The server is empty, noone is connected. '\
|
||||
'Feel free to remedy this situation'
|
||||
return text
|
||||
|
||||
def ofsGetsaveExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'Invalid directory in ofs-getsave.py. Please configure it accordingly',
|
||||
0x02 :'Couldn\'t save game to disk',
|
||||
0x03 :'URL did not lead to a valid savegame. Please check the url in your browser',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsStartExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'OpenTTD appears to be running already. Try !apconnect instead',
|
||||
0x02 :'OpenTTD was started succesfully, but openttd.pid could not be updated',
|
||||
0x03 :'Could not start OpenTTD. Check the configuration of ofs-start.py',
|
||||
0x04 :'Started OpenTTD, but couldn\'t read a valid pid from the output. Likely something went wrong',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsSvnToBinExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'Copying the new executable to the server directory did not succeed',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsSvnUpdateExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'Source directory does not seem to exist. Please check ofs-svnupdate.py configuration',
|
||||
0x02 :'Invalid branch selected in ofs-svnupdate.py\'s configuration. Please use nightlies/trunk, stable or testing',
|
||||
0x03 :'Something went wrong executing make or svn. Please run ofs-svnupdate.py manually and see what goes wrong',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def ofsTransferSaveExitcodeToText(number):
|
||||
texts = {
|
||||
0x00 :'',
|
||||
0x01 :'File already exists, not transferring savegame',
|
||||
0x02 :'Missing either game ID or savegame, or possibly both',
|
||||
0x03 :'SSH configuration invalid. Please review ofs-transfersave.py\'s configuration',
|
||||
0x04 :'Couldn\'t find file, please specify a valid savegame',
|
||||
0x05 :'Failed to trasfer the savegame. Please run ofs-transfersave manually to see what causes this',
|
||||
}
|
||||
text = texts.get(number, number)
|
||||
return text
|
||||
|
||||
def refreshConnection(connections, registeredConnections, conn):
|
||||
try:
|
||||
del registeredConnections[conn.filenumber]
|
||||
except KeyError:
|
||||
pass
|
||||
newconn = conn.copy()
|
||||
connections[conn.channel] = newconn
|
||||
return newconn
|
||||
|
||||
def vehicleCount(companies):
|
||||
rail = road = water = air = 0
|
||||
for company in list(companies.values()):
|
||||
if not company.id == 255:
|
||||
rail += company.vehicles.train
|
||||
road += (company.vehicles.lorry + company.vehicles.bus)
|
||||
water += company.vehicles.ship
|
||||
air += company.vehicles.plane
|
||||
return (rail, road, water, air)
|
||||
|
Loading…
Reference in New Issue