-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow social event exchange anonymous between clients, MQTT broker will hide users' ip and personal information. #3400
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from logging_handler import LoggingHandler | ||
from socketio_handler import SocketIoHandler | ||
from colored_logging_handler import ColoredLoggingHandler | ||
from social_handler import SocialHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from pokemongo_bot.event_manager import EventHandler | ||
import thread | ||
import paho.mqtt.client as mqtt | ||
class MyMQTTClass: | ||
def __init__(self, clientid=None): | ||
self._mqttc = mqtt.Client(clientid) | ||
self._mqttc.on_message = self.mqtt_on_message | ||
#self._mqttc.on_connect = self.mqtt_on_connect | ||
#self._mqttc.on_publish = self.mqtt_on_publish | ||
#self._mqttc.on_subscribe = self.mqtt_on_subscribe | ||
#def mqtt_on_connect(self, mqttc, obj, flags, rc): | ||
#print "rc: "+str(rc) | ||
def mqtt_on_message(self, mqttc, obj, msg): | ||
print msg.topic+" "+str(msg.qos)+" "+str(msg.payload) | ||
#def mqtt_on_publish(self, mqttc, obj, mid): | ||
#print "mid: "+str(mid) | ||
#def mqtt_on_subscribe(self, mqttc, obj, mid, granted_qos): | ||
# print "Subscribed: "+str(mid)+" "+str(granted_qos) | ||
#def mqtt_on_log(self, mqttc, obj, level, string): | ||
# print string | ||
def publish(self, channel, message): | ||
self._mqttc.publish(channel, message) | ||
def connect_to_mqtt(self): | ||
self._mqttc.connect("test.mosca.io", 1883, 60) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in the config file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, welcome to contribute on the branch. |
||
self._mqttc.subscribe("$GOF/Social/#", 0) | ||
def run(self): | ||
self._mqttc.loop_forever() | ||
class SocialHandler(EventHandler): | ||
def __init__(self): | ||
self.mqttc = MyMQTTClass() | ||
self.mqttc.connect_to_mqtt() | ||
thread.start_new_thread(self.mqttc.run) | ||
def handle_event(self, event, sender, level, formatted_msg, data): | ||
#sender_name = type(sender).__name__ | ||
if formatted_msg: | ||
message = "[{}] {}".format(event, formatted_msg) | ||
else: | ||
message = '{}: {}'.format(event, str(data)) | ||
if event == 'catchable_pokemon': | ||
self.mqttc.publish("$GOF/Social/Catchable", message) | ||
#print 'have catchable_pokemon' | ||
#print message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ mock==2.0.0 | |
timeout-decorator==0.3.2 | ||
raven==5.23.0 | ||
demjson==2.2.4 | ||
paho-mqtt==1.2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference from:
https://eclipse.googlesource.com/paho/org.eclipse.paho.mqtt.python/+/1.1/examples/sub-class.py
And username/password for deployment:
http://www.hivemq.com/blog/mqtt-security-fundamentals-authentication-username-password