Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
syntax_j
mycard
Commits
c1f6f124
Commit
c1f6f124
authored
Jul 26, 2012
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xmpp
parent
7be8d5bf
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
172 additions
and
91 deletions
+172
-91
lib/game.rb
lib/game.rb
+3
-0
lib/iduel/game.rb
lib/iduel/game.rb
+3
-0
lib/window_chat.rb
lib/window_chat.rb
+1
-3
lib/ygocore/event.rb
lib/ygocore/event.rb
+13
-13
lib/ygocore/game.rb
lib/ygocore/game.rb
+152
-75
No files found.
lib/game.rb
View file @
c1f6f124
...
...
@@ -39,6 +39,9 @@ class Game
def
refresh_interval
5
end
def
show_chat_self
false
end
end
lib/iduel/game.rb
View file @
c1f6f124
...
...
@@ -124,6 +124,9 @@ class Iduel < Game
end
end
end
def
show_chat_self
true
end
private
def
connect
require
'socket'
...
...
lib/window_chat.rb
View file @
c1f6f124
...
...
@@ -27,11 +27,9 @@ class Window_Chat < Window_Scrollable
if
!
@chat_input
.
value
.
empty?
chatmessage
=
ChatMessage
.
new
(
$game
.
user
,
@chat_input
.
value
,
@channel
)
$game
.
chat
chatmessage
Game_Event
.
push
Game_Event
::
Chat
.
new
(
chatmessage
)
Game_Event
.
push
Game_Event
::
Chat
.
new
(
chatmessage
)
if
$game
.
show_chat_self
true
end
when
:ESC
true
end
end
@chat_input
.
refresh
...
...
lib/ygocore/event.rb
View file @
c1f6f124
...
...
@@ -7,8 +7,8 @@ class Game_Event
else
Error
.
new
(
'登录'
,
'用户名或密码错误'
)
end
when
:users
AllUsers
.
new
data
.
collect
{
|
user
|
parse_user
(
user
)}
#
when :users
#
AllUsers.new data.collect{|user|parse_user(user)}
when
:rooms
rooms_wait
=
[]
rooms_start
=
[]
...
...
@@ -21,21 +21,21 @@ class Game_Event
end
end
AllRooms
.
new
rooms_wait
+
rooms_start
when
:newuser
NewUser
.
new
parse_user
data
when
:missinguser
MissingUser
.
new
parse_user
data
#
when :newuser
#
NewUser.new parse_user data
#
when :missinguser
#
MissingUser.new parse_user data
when
:newroom
NewRoom
.
new
parse_room
data
when
:missingroom
MissingRoom
.
new
parse_room
data
when
:chat
case
data
[
:channel
]
when
:lobby
Chat
.
new
ChatMessage
.
new
User
.
new
(
data
[
:from
][
:id
],
data
[
:from
][
:name
]),
data
[
:message
],
:lobby
else
Chat
.
new
ChatMessage
.
new
User
.
new
(
data
[
:from
][
:id
],
data
[
:from
][
:name
]),
data
[
:message
],
User
.
new
(
data
[
:channel
])
end
#
when :chat
#
case data[:channel]
#
when :lobby
#
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], :lobby
#
else
#
Chat.new ChatMessage.new User.new(data[:from][:id],data[:from][:name]), data[:message], User.new(data[:channel])
#
end
end
end
def
self
.
parse_room
(
room
)
...
...
lib/ygocore/game.rb
View file @
c1f6f124
...
...
@@ -15,6 +15,8 @@ class Ygocore < Game
load
'lib/ygocore/room.rb'
load
'lib/ygocore/scene_lobby.rb'
require
'json'
require
'xmpp4r/client'
require
'xmpp4r/muc'
end
def
refresh_interval
...
...
@@ -24,7 +26,52 @@ class Ygocore < Game
def
login
(
username
,
password
)
@username
=
username
@password
=
password
@nickname_conflict
=
[]
@@im
=
Jabber
::
Client
.
new
(
Jabber
::
JID
::
new
(
@username
,
'my-card.in'
,
'mycard'
))
@@im_room
=
Jabber
::
MUC
::
MUCClient
.
new
(
@@im
)
#Jabber.debug = true
@@im
.
on_exception
do
|
exception
,
c
,
where
|
$log
.
error
(
'聊天出错'
)
{
[
exception
,
c
,
where
]
}
if
where
==
:close
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天连接断开, 可能是网络问题或帐号从其他地点登录'
)))
else
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天连接断开, 5秒后重新连接'
)))
sleep
5
im_connect
end
end
@@im_room
.
add_message_callback
do
|
m
|
user
=
m
.
from
.
resource
==
nickname
?
@user
:
User
.
new
(
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
)
Game_Event
.
push
Game_Event
::
Chat
.
new
ChatMessage
.
new
(
user
,
m
.
body
,
:lobby
)
rescue
$log
.
error
(
'收到聊天消息'
)
{
$!
}
end
@@im_room
.
add_private_message_callback
do
|
m
|
if
m
.
body
#忽略无消息的正在输入等内容
user
=
m
.
from
.
resource
==
nickname
?
@user
:
User
.
new
(
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
)
Game_Event
.
push
Game_Event
::
Chat
.
new
ChatMessage
.
new
(
user
,
m
.
body
,
user
)
rescue
$log
.
error
(
'收到私聊消息'
)
{
$!
}
end
end
@@im_room
.
add_join_callback
do
|
m
|
Game_Event
.
push
Game_Event
::
NewUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
end
@@im_room
.
add_leave_callback
do
|
m
|
Game_Event
.
push
Game_Event
::
MissingUser
.
new
User
.
new
m
.
from
.
resource
.
to_sym
,
m
.
from
.
resource
end
connect
im_connect
end
def
nickname
return
@nickname
if
@nickname
if
@nickname_conflict
.
include?
@username
1
.
upto
(
9
)
do
|
i
|
result
=
"
#{
@username
}
-
#{
i
}
"
return
result
unless
@nickname_conflict
.
include?
result
end
raise
'can`t get available nickname'
else
@username
end
end
def
connect
...
...
@@ -35,12 +82,42 @@ class Ygocore < Game
end
end
def
im_connect
Thread
.
new
{
begin
@@im
.
allow_tls
=
false
@@im
.
use_ssl
=
true
@@im
.
connect
(
'my-card.in'
,
5223
)
#ruby19/windows下 使用tls连接时会卡住
@@im
.
auth
(
@password
)
@@im
.
send
(
Jabber
::
Presence
.
new
.
set_type
(
:available
))
begin
nickname
=
nickname
()
@@im_room
.
join
(
Jabber
::
JID
.
new
(
'lobby@conference.my-card.in/'
+
nickname
))
rescue
Jabber
::
ServerError
=>
exception
if
exception
.
error
.
error
==
'conflict'
@nickname_conflict
<<
nickname
retry
end
end
Game_Event
.
push
Game_Event
::
AllUsers
.
new
@@im_room
.
roster
.
keys
.
collect
{
|
nick
|
User
.
new
(
nick
.
to_sym
,
nick
)
}
rescue
p
$!
rescue
StandardError
=>
exception
$log
.
error
(
'聊天连接出错'
)
{
exception
}
Game_Event
.
push
(
Game_Event
::
Chat
.
new
(
ChatMessage
.
new
(
User
.
new
(
:system
,
'System'
),
'聊天服务器连接失败'
)))
end
}
end
def
chat
(
chatmessage
)
case
chatmessage
.
channel
when
:lobby
send
(
:chat
,
channel: :lobby
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
msg
=
Jabber
::
Message
::
new
(
nil
,
chatmessage
.
message
)
@@im_room
.
send
msg
when
User
send
(
:chat
,
channel:
chatmessage
.
channel
.
id
,
message:
chatmessage
.
message
,
time:
chatmessage
.
time
)
msg
=
Jabber
::
Message
::
new
(
nil
,
chatmessage
.
message
)
@@im_room
.
send
msg
,
chatmessage
.
channel
.
id
#send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment