synacrb 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30dbae35dd723e6b899621986b3a0399393cd8c9
4
- data.tar.gz: ffcffa2fdbd971f00a753b2b0b58ee5a22d23557
3
+ metadata.gz: b804a81c7a3b8bab7a38706572dc0fd24deccd8f
4
+ data.tar.gz: 1ea9553f4eecdb3fec32238421cd7be7a8f9d0f3
5
5
  SHA512:
6
- metadata.gz: 55186b9bd1332c6803c7ab07038a11e5fc74107ef6283895545266d533b87e73ff5587147f6178cb58f99adc94f860bc81fa8599abc053c16f81236b940e4491
7
- data.tar.gz: ea49876c0be8dbf2d13d1d6c4b080474ab2e14378aa4bebecbf1f23ba0f2fad91057f39839a81731bf08ba5e4a22a3099a7b464b30294b5404eca3970614056b
6
+ metadata.gz: e4dd2dc9beec7421a801facffcff1ad87bf3708123584c974336ac44e080cb9de626d8e83c2e4d31d3d3028cb89a9b81c7cba3e6a2c1b6bdc29145d803ab4963
7
+ data.tar.gz: d30008e3e3210856ae7a88e8f3c70bf2db87e1418f09a84ad08cefa32090b335254fefcf020dd7cd5280b1b88ce5e20d65a481b8285509d6430871c2ace6edc3
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  synacrb-*.gem
10
+ /lib/test.rb
data/Gemfile CHANGED
@@ -2,8 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- gem "msgpack"
6
- gem "openssl"
7
-
8
5
  # Specify your gem's dependencies in synacrb.gemspec
9
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synacrb (0.1.0)
4
+ synacrb (0.2.0)
5
+ msgpack (~> 1.2)
6
+ openssl (~> 2.1)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
9
- msgpack (1.1.0)
10
- openssl (2.0.6)
11
+ msgpack (1.2.0)
12
+ openssl (2.1.0)
11
13
  rake (10.5.0)
12
14
 
13
15
  PLATFORMS
@@ -15,8 +17,6 @@ PLATFORMS
15
17
 
16
18
  DEPENDENCIES
17
19
  bundler (~> 1.16)
18
- msgpack
19
- openssl
20
20
  rake (~> 10.0)
21
21
  synacrb!
22
22
 
@@ -6,76 +6,65 @@ module Synacrb
6
6
 
7
7
  LIMIT_USER_NAME = 128
8
8
  LIMIT_CHANNEL_NAME = 128
9
- LIMIT_GROUP_NAME = 128
10
- LIMIT_GROUP_AMOUNT = 2048
11
9
  LIMIT_MESSAGE = 16384
12
10
 
13
11
  LIMIT_BULK = 64
14
12
 
15
- ERR_GROUP_INVALID_POS = 1
16
- ERR_GROUP_LOCKED_NAME = 2
17
- ERR_LIMIT_REACHED = 3
18
- ERR_LOGIN_BANNED = 4
19
- ERR_LOGIN_BOT = 5
20
- ERR_LOGIN_INVALID = 6
21
- ERR_MAX_CONN_PER_IP = 7
22
- ERR_MISSING_FIELD = 8
23
- ERR_MISSING_PERMISSION = 9
24
- ERR_NAME_TAKEN = 10
25
- ERR_UNKNOWN_BOT = 11
26
- ERR_UNKNOWN_CHANNEL = 12
27
- ERR_UNKNOWN_GROUP = 13
28
- ERR_UNKNOWN_MESSAGE = 14
29
- ERR_UNKNOWN_USER = 15
13
+ ERR_LIMIT_REACHED = 1
14
+ ERR_LOGIN_BANNED = 2
15
+ ERR_LOGIN_BOT = 3
16
+ ERR_LOGIN_INVALID = 4
17
+ ERR_MAX_CONN_PER_IP = 5
18
+ ERR_MISSING_FIELD = 6
19
+ ERR_MISSING_PERMISSION = 7
20
+ ERR_NAME_TAKEN = 8
21
+ ERR_UNKNOWN_BOT = 9
22
+ ERR_UNKNOWN_CHANNEL = 10
23
+ ERR_UNKNOWN_MESSAGE = 11
24
+ ERR_UNKNOWN_USER = 12
30
25
 
31
- PERM_READ = 1
32
- PERM_WRITE = 1 << 1
26
+ PERM_READ = 1
27
+ PERM_WRITE = 1 << 1
33
28
 
34
- PERM_ASSIGN_GROUPS = 1 << 2
35
- PERM_BAN = 1 << 3
36
- PERM_MANAGE_CHANNELS = 1 << 4
37
- PERM_MANAGE_GROUPS = 1 << 5
38
- PERM_MANAGE_MESSAGES = 1 << 6
29
+ PERM_MANAGE_CHANNELS = 1 << 2
30
+ PERM_MANAGE_MESSAGES = 1 << 3
31
+ PERM_MANAGE_MODES = 1 << 4
39
32
 
40
- Channel = Struct.new(:id, :name, :overrides)
41
- Group = Struct.new(:allow, :deny, :id, :name, :pos, :unassignable)
33
+ PERM_ALL = PERM_READ | PERM_WRITE | PERM_MANAGE_CHANNELS | PERM_MANAGE_MESSAGES | PERM_MANAGE_MODES;
34
+
35
+ Channel = Struct.new(:default_mode_bot, :default_mode_user, :id, :name)
42
36
  Message = Struct.new(:author, :channel, :id, :text, :timestamp, :timestamp_edit)
43
- User = Struct.new(:ban, :bot, :groups, :id, :name)
37
+ User = Struct.new(:admin, :ban, :bot, :id, :modes, :name)
44
38
 
45
39
  # CLIENT PACKETS
46
- PACKET_CLOSE_ID = 0; Close = Class.new
47
- PACKET_ERR_ID = 1;
48
- PACKET_RATELIMIT_ID = 2;
49
- PACKET_CHANNELCREATE_ID = 3; ChannelCreate = Struct.new(:name, :overrides)
50
- PACKET_CHANNELDELETE_ID = 4; ChannelDelete = Struct.new(:id)
51
- PACKET_CHANNELUPDATE_ID = 5; ChannelUpdate = Struct.new(:inner, :keep_overrides)
52
- PACKET_COMMAND_ID = 6; Command = Struct.new(:args, :recipient)
53
- PACKET_GROUPCREATE_ID = 7; GroupCreate = Struct.new(:allow, :deny, :name, :pos, :unassignable)
54
- PACKET_GROUPDELETE_ID = 8; GroupDelete = Struct.new(:id)
55
- PACKET_GROUPUPDATE_ID = 9; GroupUpdate = Struct.new(:inner)
56
- PACKET_LOGIN_ID = 10; Login = Struct.new(:bot, :name, :password, :token)
57
- PACKET_LOGINUPDATE_ID = 11; LoginUpdate = Struct.new(:name, :password_current, :password_new, :reset_token)
58
- PACKET_MESSAGECREATE_ID = 12; MessageCreate = Struct.new(:channel, :text)
59
- PACKET_MESSAGEDELETE_ID = 13; MessageDelete = Struct.new(:id)
60
- PACKET_MESSAGEDELETEBULK_ID = 14; MessageDeleteBulk = Struct.new(:channel, :ids)
61
- PACKET_MESSAGELIST_ID = 15; MessageList = Struct.new(:after, :before, :channel, :limit)
62
- PACKET_MESSAGEUPDATE_ID = 16; MessageUpdate = Struct.new(:id, :text)
63
- PACKET_PRIVATEMESSAGE_ID = 17; PrivateMessage = Struct.new(:text, :recipient)
64
- PACKET_TYPING_ID = 18; Typing = Struct.new(:channel)
65
- PACKET_USERUPDATE_ID = 19; UserUpdate = Struct.new(:ban, :groups, :id)
40
+ PACKET_CLOSE_ID = 0; Close = Class.new
41
+ PACKET_ERR_ID = 1;
42
+ PACKET_RATELIMIT_ID = 2;
43
+ PACKET_CHANNELCREATE_ID = 3; ChannelCreate = Struct.new(:default_mode_bot, :default_mode_user, :name)
44
+ PACKET_CHANNELDELETE_ID = 4; ChannelDelete = Struct.new(:id)
45
+ PACKET_CHANNELUPDATE_ID = 5; ChannelUpdate = Struct.new(:inner)
46
+ PACKET_COMMAND_ID = 6; Command = Struct.new(:args, :recipient)
47
+ PACKET_LOGIN_ID = 7; Login = Struct.new(:bot, :name, :password, :token)
48
+ PACKET_LOGINUPDATE_ID = 8; LoginUpdate = Struct.new(:name, :password_current, :password_new, :reset_token)
49
+ PACKET_MESSAGECREATE_ID = 9; MessageCreate = Struct.new(:channel, :text)
50
+ PACKET_MESSAGEDELETE_ID = 10; MessageDelete = Struct.new(:id)
51
+ PACKET_MESSAGEDELETEBULK_ID = 11; MessageDeleteBulk = Struct.new(:channel, :ids)
52
+ PACKET_MESSAGELIST_ID = 12; MessageList = Struct.new(:after, :before, :channel, :limit)
53
+ PACKET_MESSAGEUPDATE_ID = 13; MessageUpdate = Struct.new(:id, :text)
54
+ PACKET_PRIVATEMESSAGE_ID = 14; PrivateMessage = Struct.new(:text, :recipient)
55
+ PACKET_TYPING_ID = 15; Typing = Struct.new(:channel)
56
+ PACKET_USERUPDATE_ID = 16; UserUpdate = Struct.new(:admin, :ban, :channel_mode, :id)
66
57
 
67
58
  # SERVER PACKETS
68
- PACKET_CHANNELDELETERECEIVE_ID = 20; ChannelDeleteReceive = Struct.new(:inner)
69
- PACKET_CHANNELRECEIVE_ID = 21; ChannelReceive = Struct.new(:inner)
70
- PACKET_COMMANDRECEIVE_ID = 22; CommandReceive = Struct.new(:args, :author)
71
- PACKET_GROUPDELETERECEIVE_ID = 23; GroupDeleteReceive = Struct.new(:inner)
72
- PACKET_GROUPRECEIVE_ID = 24; GroupReceive = Struct.new(:inner, :new)
73
- PACKET_LOGINSUCCESS_ID = 25; LoginSuccess = Struct.new(:created, :id, :token)
74
- PACKET_MESSAGEDELETERECEIVE_ID = 26; MessageDeleteReceive = Struct.new(:id)
75
- PACKET_MESSAGERECEIVE_ID = 27; MessageReceive = Struct.new(:inner, :new)
76
- PACKET_PMRECEIVE_ID = 28; PMReceive = Struct.new(:author, :text)
77
- PACKET_TYPINGRECEIVE_ID = 29; TypingReceive = Struct.new(:author, :channel)
78
- PACKET_USERRECEIVE_ID = 30; UserReceive = Struct.new(:inner)
59
+ PACKET_CHANNELDELETERECEIVE_ID = 17; ChannelDeleteReceive = Struct.new(:inner)
60
+ PACKET_CHANNELRECEIVE_ID = 18; ChannelReceive = Struct.new(:inner)
61
+ PACKET_COMMANDRECEIVE_ID = 19; CommandReceive = Struct.new(:args, :author)
62
+ PACKET_LOGINSUCCESS_ID = 20; LoginSuccess = Struct.new(:created, :id, :token)
63
+ PACKET_MESSAGEDELETERECEIVE_ID = 21; MessageDeleteReceive = Struct.new(:id)
64
+ PACKET_MESSAGERECEIVE_ID = 22; MessageReceive = Struct.new(:inner, :new)
65
+ PACKET_PMRECEIVE_ID = 23; PMReceive = Struct.new(:author, :text)
66
+ PACKET_TYPINGRECEIVE_ID = 24; TypingReceive = Struct.new(:author, :channel)
67
+ PACKET_USERRECEIVE_ID = 25; UserReceive = Struct.new(:inner)
79
68
 
80
69
  def self.encode_u16(input)
81
70
  (input >> 8).chr + (input % 256).chr
@@ -96,12 +85,6 @@ module Synacrb
96
85
  ChannelUpdate
97
86
  when PACKET_COMMAND_ID
98
87
  Command
99
- when PACKET_GROUPCREATE_ID
100
- GroupCreate
101
- when PACKET_GROUPDELETE_ID
102
- GroupDelete
103
- when PACKET_GROUPUPDATE_ID
104
- GroupUpdate
105
88
  when PACKET_LOGIN_ID
106
89
  Login
107
90
  when PACKET_LOGINUPDATE_ID
@@ -128,10 +111,6 @@ module Synacrb
128
111
  ChannelReceive
129
112
  when PACKET_COMMANDRECEIVE_ID
130
113
  CommandReceive
131
- when PACKET_GROUPDELETERECEIVE_ID
132
- GroupDeleteReceive
133
- when PACKET_GROUPRECEIVE_ID
134
- GroupReceive
135
114
  when PACKET_LOGINSUCCESS_ID
136
115
  LoginSuccess
137
116
  when PACKET_MESSAGEDELETERECEIVE_ID
@@ -157,12 +136,6 @@ module Synacrb
157
136
  PACKET_CHANNELUPDATE_ID
158
137
  elsif packet.instance_of? Command
159
138
  PACKET_COMMAND_ID
160
- elsif packet.instance_of? GroupCreate
161
- PACKET_GROUPCREATE_ID
162
- elsif packet.instance_of? GroupDelete
163
- PACKET_GROUPDELETE_ID
164
- elsif packet.instance_of? GroupUpdate
165
- PACKET_GROUPUPDATE_ID
166
139
  elsif packet.instance_of? Login
167
140
  PACKET_LOGIN_ID
168
141
  elsif packet.instance_of? LoginUpdate
@@ -189,10 +162,6 @@ module Synacrb
189
162
  PACKET_CHANNELRECEIVE_ID
190
163
  elsif packet.instance_of? CommandReceive
191
164
  PACKET_COMMANDRECEIVE_ID
192
- elsif packet.instance_of? GroupDeleteReceive
193
- PACKET_GROUPDELETERECEIVE_ID
194
- elsif packet.instance_of? GroupReceive
195
- PACKET_GROUPRECEIVE_ID
196
165
  elsif packet.instance_of? LoginSuccess
197
166
  PACKET_LOGINSUCCESS_ID
198
167
  elsif packet.instance_of? MessageDeleteReceive
@@ -0,0 +1,32 @@
1
+ module Synacrb
2
+ class State
3
+ def initialize
4
+ @channels = {}
5
+ @users = {}
6
+ end
7
+ def channels
8
+ @channels
9
+ end
10
+ def users
11
+ @users
12
+ end
13
+ def update(packet)
14
+ if packet.instance_of? Common::ChannelDeleteReceive
15
+ unless packet.inner.instance_of? Common::Channel
16
+ packet.inner = Common::Channel.new(*packet.inner)
17
+ end
18
+ @channels.delete packet.inner.id
19
+ elsif packet.instance_of? Common::ChannelReceive
20
+ unless packet.inner.instance_of? Common::Channel
21
+ packet.inner = Common::Channel.new(*packet.inner)
22
+ end
23
+ @channels[packet.inner.id] = packet.inner
24
+ elsif packet.instance_of? Common::UserReceive
25
+ unless packet.inner.instance_of? Common::User
26
+ packet.inner = Common::User.new(*packet.inner)
27
+ end
28
+ @users[packet.inner.id] = packet.inner
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Synacrb
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/synacrb.rb CHANGED
@@ -8,6 +8,17 @@ require "socket"
8
8
  require "synacrb/version"
9
9
 
10
10
  module Synacrb
11
+ # Get the mode bitmask for a user in a channel
12
+ def self.get_mode(channel, user)
13
+ if user.bot
14
+ return channel.default_mode_bot unless user.modes.include? channel.id
15
+ user.modes[channel.id]
16
+ else
17
+ return channel.default_mode_user unless user.modes.include? channel.id
18
+ user.modes[channel.id]
19
+ end
20
+ end
21
+
11
22
  class Session
12
23
  # Connect to the server
13
24
  def initialize(addr, hash, &callback)
data/synacrb.gemspec CHANGED
@@ -28,6 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
+ spec.add_runtime_dependency "msgpack", "~> 1.2"
32
+ spec.add_runtime_dependency "openssl", "~> 2.1"
33
+
31
34
  spec.add_development_dependency "bundler", "~> 1.16"
32
35
  spec.add_development_dependency "rake", "~> 10.0"
33
36
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synacrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jD91mZM2
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-25 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: msgpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: openssl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,10 +81,10 @@ files:
53
81
  - Rakefile
54
82
  - bin/console
55
83
  - bin/setup
56
- - lib/common.rb
57
- - lib/encrypter.rb
58
- - lib/state.rb
59
84
  - lib/synacrb.rb
85
+ - lib/synacrb/common.rb
86
+ - lib/synacrb/encrypter.rb
87
+ - lib/synacrb/state.rb
60
88
  - lib/synacrb/version.rb
61
89
  - synacrb.gemspec
62
90
  homepage: https://github.com/jD91mZM2/synacrb
@@ -79,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
107
  version: '0'
80
108
  requirements: []
81
109
  rubyforge_project:
82
- rubygems_version: 2.6.13
110
+ rubygems_version: 2.6.14
83
111
  signing_key:
84
112
  specification_version: 4
85
113
  summary: synac library for ruby.
data/lib/state.rb DELETED
@@ -1,71 +0,0 @@
1
- module Synacrb
2
- class State
3
- def initialize
4
- @channels = {}
5
- @groups = {}
6
- @users = {}
7
- end
8
- def channels
9
- @channels
10
- end
11
- def groups
12
- @groups
13
- end
14
- def users
15
- @users
16
- end
17
- def update(packet)
18
- if packet.instance_of? Common::ChannelDeleteReceive
19
- unless packet.inner.instance_of? Common::Channel
20
- packet.inner = Common::Channel.new(*packet.inner)
21
- end
22
- @channels.delete packet.inner.id
23
- elsif packet.instance_of? Common::ChannelReceive
24
- unless packet.inner.instance_of? Common::Channel
25
- packet.inner = Common::Channel.new(*packet.inner)
26
- end
27
- @channels[packet.inner.id] = packet.inner
28
- elsif packet.instance_of? Common::GroupDeleteReceive
29
- unless packet.inner.instance_of? Common::Group
30
- packet.inner = Common::Group.new(*packet.inner)
31
- end
32
- for id in @groups.each_key
33
- if @groups[id].pos > packet.inner.pos
34
- @groups[id].pos -= 1
35
- end
36
- end
37
- @groups.delete packet.inner.id
38
- elsif packet.instance_of? Common::GroupReceive
39
- unless packet.inner.instance_of? Common::Group
40
- packet.inner = Common::Group.new(*packet.inner)
41
- end
42
- if packet.new
43
- unless @groups[packet.inner.id].nil?
44
- pos = @groups[packet.inner.id].pos
45
-
46
- if packet.inner.pos > pos
47
- for id in @groups.each_key
48
- if @groups[id].pos > pos && @groups[id].pos <= packet.inner.pos
49
- @groups[id].pos -= 1
50
- end
51
- end
52
- elsif packet.inner.pos < pos
53
- for group in @groups.each_key
54
- if @groups[id].pos >= packet.inner.pos && @groups[id].pos < pos
55
- @groups[id].pos += 1
56
- end
57
- end
58
- end
59
- else
60
- for group in @groups.each_key
61
- if @groups[id].pos >= packet.inner.pos
62
- @groups[id].pos += 1
63
- end
64
- end
65
- end
66
- end
67
- @groups[packet.inner.id] = packet.inner
68
- end
69
- end
70
- end
71
- end
File without changes