Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
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
MyCard
Mirai
Commits
72e4208d
Commit
72e4208d
authored
Sep 11, 2019
by
liujiahua123123
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
c6941617
f19ea393
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
105 additions
and
50 deletions
+105
-50
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
+1
-1
mirai-core/src/main/java/net/mamoe/mirai/message/defaults/Image.kt
...e/src/main/java/net/mamoe/mirai/message/defaults/Image.kt
+10
-0
mirai-core/src/main/java/net/mamoe/mirai/network/packet/ClientPacket.kt
.../main/java/net/mamoe/mirai/network/packet/ClientPacket.kt
+10
-0
mirai-core/src/main/java/net/mamoe/mirai/network/packet/image/ClientGetGroupImageIDPacket.kt
...mirai/network/packet/image/ClientGetGroupImageIDPacket.kt
+35
-0
mirai-core/src/main/java/net/mamoe/mirai/utils/CharImageConverter.java
...c/main/java/net/mamoe/mirai/utils/CharImageConverter.java
+42
-42
mirai-core/src/main/java/net/mamoe/mirai/utils/ProtocolBuff.kt
...-core/src/main/java/net/mamoe/mirai/utils/ProtocolBuff.kt
+7
-7
No files found.
mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java
View file @
72e4208d
...
...
@@ -28,7 +28,7 @@ import java.util.concurrent.ExecutionException;
*
* @author NaturalHG
*/
public
class
MiraiServer
{
public
final
class
MiraiServer
{
private
static
MiraiServer
instance
;
public
static
MiraiServer
getInstance
()
{
...
...
mirai-core/src/main/java/net/mamoe/mirai/message/defaults/Image.kt
View file @
72e4208d
...
...
@@ -2,6 +2,8 @@ package net.mamoe.mirai.message.defaults
import
net.mamoe.mirai.message.Message
import
net.mamoe.mirai.message.MessageId
import
net.mamoe.mirai.network.packet.cutTail
import
net.mamoe.mirai.network.packet.md5
import
java.awt.image.BufferedImage
import
java.io.*
import
java.net.URL
...
...
@@ -54,4 +56,12 @@ class Image : Message {
}
return
this
.
imageID
==
another
.
imageID
}
companion
object
{
fun
getImageID
(
filename
:
String
):
ByteArray
=
md5
(
filename
).
cutTail
(
1
)
}
}
fun
main
()
{
println
(
0
xB0
)
}
\ No newline at end of file
mirai-core/src/main/java/net/mamoe/mirai/network/packet/ClientPacket.kt
View file @
72e4208d
...
...
@@ -244,4 +244,14 @@ fun DataOutputStream.writeVarByteArray(byteArray: ByteArray) {
fun
DataOutputStream
.
writeVarString
(
str
:
String
)
{
this
.
writeVarByteArray
(
str
.
toByteArray
())
}
fun
DataOutputStream
.
writeVarShort
(
short
:
Int
)
{
this
.
writeByte
(
0
x02
)
this
.
writeShort
(
short
)
}
fun
DataOutputStream
.
writeVarInt
(
int
:
Int
)
{
this
.
writeByte
(
0
x04
)
this
.
writeInt
(
int
)
}
\ No newline at end of file
mirai-core/src/main/java/net/mamoe/mirai/network/packet/image/ClientGetGroupImageIDPacket.kt
0 → 100644
View file @
72e4208d
package
net.mamoe.mirai.network.packet.image
import
net.mamoe.mirai.network.packet.*
import
net.mamoe.mirai.utils.writeProtoInt
import
java.awt.image.BufferedImage
/**
* 查询群消息的 image id.
* That is, 查询服务器上是否有这个图片, 有就返回 id, 没有就需要上传
*
* @author Him188moe
*/
@PacketId
(
"03 88"
)
@ExperimentalUnsignedTypes
class
ClientGetGroupImageIDPacket
(
val
bot
:
Long
,
val
sessionKey
:
ByteArray
,
val
group
:
Long
,
val
image
:
BufferedImage
)
:
ClientPacket
()
{
override
fun
encode
()
{
this
.
writeRandom
(
2
)
this
.
writeQQ
(
bot
)
this
.
writeHex
(
"04 00 00 00 01 01 01 00 00 68 20 00 00 00 00 00 00 00 00"
)
this
.
encryptAndWrite
(
sessionKey
)
{
it
.
writeHex
(
"00 00 00 07 00 00 00 5E 08 01 12 03 98 01 01 10 01 1A"
)
it
.
writeHex
(
"5A"
)
it
.
writeHex
(
"08"
)
it
.
writeProtoInt
(
group
)
it
.
writeHex
(
"08"
)
it
.
writeProtoInt
(
image
.
height
)
}
}
}
\ No newline at end of file
mirai-core/src/main/java/net/mamoe/mirai/utils/CharImageConverter.java
View file @
72e4208d
...
...
@@ -8,9 +8,10 @@ import java.util.concurrent.Callable;
/**
* Convert IMAGE into Chars that could shows in terminal
*
* @author NaturalHG
*/
public
class
CharImageConverter
implements
Callable
<
String
>
{
public
final
class
CharImageConverter
implements
Callable
<
String
>
{
/**
* width should depends on the width of the terminal
...
...
@@ -19,74 +20,73 @@ public class CharImageConverter implements Callable<String> {
private
int
width
;
private
double
ignoreRate
;
public
CharImageConverter
(
BufferedImage
image
,
int
width
){
this
(
image
,
width
,
0.95
);
public
CharImageConverter
(
BufferedImage
image
,
int
width
)
{
this
(
image
,
width
,
0.95
);
}
public
CharImageConverter
(
BufferedImage
image
,
int
width
,
double
ignoreRate
){
public
CharImageConverter
(
BufferedImage
image
,
int
width
,
double
ignoreRate
)
{
this
.
image
=
image
;
this
.
width
=
width
;
this
.
ignoreRate
=
ignoreRate
;
}
@Override
public
String
call
(){
/*
* resize Image
* */
int
newHeight
=
(
int
)
(
this
.
image
.
getHeight
()
*
(((
double
)
width
)
/
this
.
image
.
getWidth
()));
public
String
call
()
{
/*
* resize Image
* */
int
newHeight
=
(
int
)
(
this
.
image
.
getHeight
()
*
(((
double
)
width
)
/
this
.
image
.
getWidth
()));
Image
tmp
=
image
.
getScaledInstance
(
width
,
newHeight
,
Image
.
SCALE_SMOOTH
);
BufferedImage
dimg
=
new
BufferedImage
(
width
,
newHeight
,
BufferedImage
.
TYPE_INT_ARGB
);
Graphics2D
g2d
=
dimg
.
createGraphics
();
g2d
.
drawImage
(
tmp
,
0
,
0
,
null
);
this
.
image
=
dimg
;
int
background
=
this
.
gray
(
image
.
getRGB
(
0
,
0
));
int
background
=
gray
(
image
.
getRGB
(
0
,
0
));
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
List
<
StringBuilder
>
lines
=
new
ArrayList
<>(
this
.
image
.
getHeight
());
List
<
StringBuilder
>
lines
=
new
ArrayList
<>(
this
.
image
.
getHeight
());
int
minXPos
=
this
.
width
;
int
maxXPos
=
0
;
int
minXPos
=
this
.
width
;
int
maxXPos
=
0
;
for
(
int
y
=
0
;
y
<
image
.
getHeight
();
y
++)
{
StringBuilder
builderLine
=
new
StringBuilder
();
for
(
int
x
=
0
;
x
<
image
.
getWidth
();
x
++)
{
int
gray
=
this
.
gray
(
image
.
getRGB
(
x
,
y
));
if
(
grayCompare
(
gray
,
background
))
{
builderLine
.
append
(
" "
);
}
else
{
builderLine
.
append
(
"#"
);
if
(
x
<
minXPos
)
{
minXPos
=
x
;
}
if
(
x
>
maxXPos
)
{
maxXPos
=
x
;
}
}
}
if
(
builderLine
.
toString
().
isBlank
())
{
continue
;
}
lines
.
add
(
builderLine
);
}
for
(
int
i
=
0
;
i
<
lines
.
size
();++
i
)
{
builder
.
append
(
lines
.
get
(
i
).
substring
(
minXPos
,
maxXPos
)).
append
(
"\n"
);
for
(
int
y
=
0
;
y
<
image
.
getHeight
();
y
++)
{
StringBuilder
builderLine
=
new
StringBuilder
();
for
(
int
x
=
0
;
x
<
image
.
getWidth
();
x
++)
{
int
gray
=
gray
(
image
.
getRGB
(
x
,
y
));
if
(
grayCompare
(
gray
,
background
))
{
builderLine
.
append
(
" "
);
}
else
{
builderLine
.
append
(
"#"
);
if
(
x
<
minXPos
)
{
minXPos
=
x
;
}
if
(
x
>
maxXPos
)
{
maxXPos
=
x
;
}
}
}
if
(
builderLine
.
toString
().
isBlank
())
{
continue
;
}
lines
.
add
(
builderLine
);
}
return
builder
.
toString
();
for
(
StringBuilder
line
:
lines
)
{
builder
.
append
(
line
.
substring
(
minXPos
,
maxXPos
)).
append
(
"\n"
);
}
return
builder
.
toString
();
}
private
int
gray
(
int
rgb
)
{
private
static
int
gray
(
int
rgb
)
{
int
R
=
(
rgb
&
0xff0000
)
>>
16
;
int
G
=
(
rgb
&
0x00ff00
)
>>
8
;
int
B
=
rgb
&
0x0000ff
;
int
gray
=
(
R
*
30
+
G
*
59
+
B
*
11
+
50
)
/
100
;
return
(
R
*
30
+
G
*
59
+
B
*
11
+
50
)
/
100
;
}
public
boolean
grayCompare
(
int
g1
,
int
g2
){
return
((
double
)
Math
.
min
(
g1
,
g2
)/
Math
.
max
(
g1
,
g2
))
>=
ignoreRate
;
public
boolean
grayCompare
(
int
g1
,
int
g2
)
{
return
((
double
)
Math
.
min
(
g1
,
g2
)
/
Math
.
max
(
g1
,
g2
))
>=
ignoreRate
;
}
}
mirai-core/src/main/java/net/mamoe/mirai/utils/ProtocolBuff.kt
View file @
72e4208d
...
...
@@ -15,13 +15,13 @@ import java.io.DataOutputStream
* TODO improve
*/
@ExperimentalUnsignedTypes
fun
DataOutputStream
.
writeProtoFixedInt
(
int
:
Int
)
{
if
(
int
==
128
)
{
fun
DataOutputStream
.
writeProtoFixedInt
(
int
:
Long
)
{
if
(
int
==
0
xFFL
)
{
this
.
writeShort
(
0
x80_01
)
//unsigned//1000000010000001
return
}
this
.
writeByte
(
int
.
rem
(
128
)
+
128
)
this
.
writeByte
(
int
/
128
)
this
.
writeByte
(
(
int
.
rem
(
0
xFF
)
+
0
xFF
).
toInt
()
)
this
.
writeByte
(
(
int
/
0
xFF
).
toInt
()
)
}
/**
...
...
@@ -30,9 +30,9 @@ fun DataOutputStream.writeProtoFixedInt(int: Int) {
* TODO improve
*/
@ExperimentalUnsignedTypes
fun
DataOutputStream
.
writeProtoInt
(
int
:
Int
)
{
if
(
int
<
128
)
{
this
.
writeByte
(
int
and
0
xFF
)
//10000000
fun
DataOutputStream
.
writeProtoInt
(
int
:
Long
)
{
if
(
int
<
0
xFF
)
{
this
.
writeByte
(
(
int
and
0
xFF
).
toInt
()
)
//10000000
return
}
this
.
writeProtoFixedInt
(
int
)
...
...
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