-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebMonitorPlugin.pl
More file actions
111 lines (99 loc) · 2.85 KB
/
Copy pathwebMonitorPlugin.pl
File metadata and controls
111 lines (99 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package webMonitorPlugin;
# webMonitor - an HTTP interface to monitor bots
# Copyright (C) 2006 kaliwanagan
#
# 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.
#############################################
# webMonitorV2 - Web interface to monitor yor bots
# Copyright (C) 2012 BonScott
# thanks to iMikeLance
#
# ------------------------------
# How use:
#
# Install the following packages:
#
# Protocol::WebSocket
# JSON::Any
# JSON::PP
# Wx
# File::ReadBackwards
#
# Add in your config.txt
#
# webBind localhost
# webPort XXXX
# webMapURL http://www.ragdata.com/images/maps/%s.jpg
#
# Where XXXX is a number of your choice. Ex:
# webPort 1020
#
# If webPort not defined in config, the default port is 1025
# ------------------------------
# Set only one port for each bot. For more details, visit:
# [OpenKoreBR]
# http://openkore.com.br/index.php?/topic/3189-webmonitor-v2-by-bonscott/
# [OpenKore International]
# http://forums.openkore.com/viewtopic.php?f=34&t=18264
#############################################
use strict;
use Plugins;
use Settings;
our $path;
BEGIN {
$path = $Plugins::current_plugin_folder;
}
use lib $path;
use webMonitorServer;
use Globals;
use Log qw(warning message error);
# Initialize some variables as well as plugin hooks
my $port;
my $bind;
my $webserver;
our $socketServer;
Plugins::register('webMonitor', 'Web interface to monitor yor bots', \&Unload);
my $hook = Plugins::addHooks(
['mainLoop_post', \&mainLoop],
['start3', \&post_loading],
);
sub Unload {
Plugins::delHooks($hook);
}
##### Seting webServer after of plugins loads
sub post_loading {
$port = $config{webPort} || 1025;
$bind = $config{webBind} || "localhost";
eval {
$webserver = new webMonitorServer($port, $bind);
};
unless ($webserver) {
error "webMonitor failed to start: $@\n";
Unload;
}
eval {
require WebMonitor::WebSocketServer;
$socketServer = new WebMonitor::WebSocketServer(undef, $bind);
};
unless ($socketServer) {
error "WebSocket server failed to start: $@\n"
}
}
sub mainLoop {
return if !$webserver;
$webserver->iterate;
$socketServer->iterate if $socketServer;
}
1;