优化代码

This commit is contained in:
czp3009 2018-07-31 19:26:19 +08:00
parent f010aa77ef
commit d08d1fbd8c
32 changed files with 320 additions and 454 deletions

View File

@ -28,6 +28,9 @@ B站不少参数都是瞎取的, 并且不统一, 经常混用, 以下给出一
| roomId | 直播间的真实 ID(直播房间号在 1000 以下的房间, 真实 ID 是另外一个数字) |
| cid | 直播间 ID(URL 上的短房间号以及真实房间号都叫 cid) |
| ruid | 直播间房主的用户 ID |
| rcost | 该房间内消费的瓜子数量 |
(上表仅供其他开发者参照, 本调用库中已经封装为 Java 标准全写小驼峰命名法, 例如 userId, roomId, roomUserId)
# 使用
## RESTFul API
@ -317,54 +320,54 @@ API 文档
所有的事件(有些数据包我也不知道它里面的一些值是什么含义, /record 目录下面有抓取到的 Json, 可以用来查看):
| 事件 | 抛出条件 |
| :--- | :--- |
| ActivityEventPackageEvent | 收到 ACTIVITY_EVENT 数据包 |
| ChangeRoomInfoPackageEvent | 收到 CHANGE_ROOM_INFO 数据包 |
| ComboEndPackageEvent | 收到 COMBO_END 数据包 |
| ComboSendPackageEvent | 收到 COMBO_SEND 数据包 |
| ConnectionCloseEvent | 连接断开(主动或被动) |
| ConnectSucceedEvent | 进房成功 |
| CutOffPackageEvent | 收到 CUT_OFF 数据包 |
| DanMuMsgPackageEvent | 收到 DANMU_MSG 数据包 |
| EntryEffectPackageEvent | 收到 ENTRY_EFFECT 数据包 |
| EventCmdPackageEvent | 收到 EVENT_CMD 数据包 |
| GuardBuyPackageEvent | 收到 GUARD_BUY 数据包 |
| GuardMsgPackageEvent | 收到 GUARD_MSG 数据包 |
| LivePackageEvent | 收到 LIVE 数据包 |
| PkAgainPackageEvent | 收到 PK_AGAIN 数据包 |
| PkClickAgainPackageEvent | 收到 PK_CLICK_AGAIN 数据包 |
| PkEndPackageEvent | 收到 PK_END 数据包 |
| PkMatchPackageEvent | 收到 PK_MATCH 数据包 |
| PkMicEndPackageEvent | 收到 PK_MIC_END 数据包 |
| PkPrePackageEvent | 收到 PK_PRE 数据包 |
| PkProcessPackageEvent | 收到 PK_PROCESS 数据包 |
| PkSettlePackageEvent | 收到 PK_SETTLE 数据包 |
| PkStartPackageEvent | 收到 PK_START 数据包 |
| PreparingPackageEvent | 收到 PREPARING 数据包 |
| RaffleEndPackageEvent | 收到 RAFFLE_END 数据包 |
| RaffleStartPackageEvent | 收到 RAFFLE_START 数据包 |
| ReceiveDataPackageDebugEvent | 该事件用于调试, 收到任何 Data 数据包时都会触发 |
| RoomAdminsPackageEvent | 收到 ROOM_ADMINS 数据包 |
| RoomBlockMsgPackageEvent | 收到 ROOM_BLOCK_MSG 数据包 |
| RoomLockPackageEvent | 收到 ROOM_LOCK 数据包 |
| RoomRankPackageEvent | 收到 ROOM_RANK 数据包 |
| RoomShieldPackageEvent | 收到 ROOM_SHIELD 数据包 |
| RoomSilentOffPackageEvent | 收到 ROOM_SILENT_OFF 数据包 |
| RoomSilentOnPackageEvent | 收到 ROOM_SILENT_ON 数据包 |
| SendGiftPackageEvent | 收到 SEND_GIFT 数据包 |
| SendHeartBeatPackageEvent | 每次发送心跳包后触发一次 |
| SpecialGiftPackageEvent | 收到 SPECIAL_GIFT 数据包 |
| SysGiftPackageEvent | 收到 SYS_GIFT 数据包 |
| SysMsgPackageEvent | 收到 SYS_MSG 数据包 |
| TVEndPackageEvent | 收到 TV_END 数据包 |
| TVStartPackageEvent | 收到 TV_START 数据包 |
| UnknownPackageEvent | B站新增了新种类的数据包, 出现此情况请提交 issue |
| ViewerCountPackageEvent | 收到 房间人数 数据包(不是 Json) |
| WelcomeActivityPackageEvent | 收到 WELCOME_ACTIVITY 数据包 |
| WelcomeGuardPackageEvent | 收到 WELCOME_GUARD 数据包 |
| WelcomePackageEvent | 收到 WELCOME 数据包 |
| WishBottlePackageEvent | 收到 WISH_BOTTLE 数据包 |
| 事件 | 抛出条件 | 含义 |
| :--- | :--- | :--- |
| ActivityEventPackageEvent | 收到 ACTIVITY_EVENT 数据包 | 活动事件 |
| ChangeRoomInfoPackageEvent | 收到 CHANGE_ROOM_INFO 数据包 | 更换房间背景图片 |
| ComboEndPackageEvent | 收到 COMBO_END 数据包 | 礼物连发结束 |
| ComboSendPackageEvent | 收到 COMBO_SEND 数据包 | 礼物连发开始 |
| ConnectionCloseEvent | 连接断开(主动或被动) | |
| ConnectSucceedEvent | 进房成功 | |
| CutOffPackageEvent | 收到 CUT_OFF 数据包 | 被 B站 管理员强制中断 |
| DanMuMsgPackageEvent | 收到 DANMU_MSG 数据包 | 弹幕消息 |
| EntryEffectPackageEvent | 收到 ENTRY_EFFECT 数据包 | 尚不明确 |
| EventCmdPackageEvent | 收到 EVENT_CMD 数据包 | 尚不明确 |
| GuardBuyPackageEvent | 收到 GUARD_BUY 数据包 | 船票购买 |
| GuardMsgPackageEvent | 收到 GUARD_MSG 数据包 | 舰队消息(登船) |
| LivePackageEvent | 收到 LIVE 数据包 | 开始直播 |
| PkAgainPackageEvent | 收到 PK_AGAIN 数据包 | 下面几个都是 PK 有关的事件 |
| PkClickAgainPackageEvent | 收到 PK_CLICK_AGAIN 数据包 | |
| PkEndPackageEvent | 收到 PK_END 数据包 | |
| PkMatchPackageEvent | 收到 PK_MATCH 数据包 | |
| PkMicEndPackageEvent | 收到 PK_MIC_END 数据包 | |
| PkPrePackageEvent | 收到 PK_PRE 数据包 | |
| PkProcessPackageEvent | 收到 PK_PROCESS 数据包 | |
| PkSettlePackageEvent | 收到 PK_SETTLE 数据包 | |
| PkStartPackageEvent | 收到 PK_START 数据包 | |
| PreparingPackageEvent | 收到 PREPARING 数据包 | 停止直播 |
| RaffleEndPackageEvent | 收到 RAFFLE_END 数据包 | 抽奖结束(小奖, 通常是不定期活动) |
| RaffleStartPackageEvent | 收到 RAFFLE_START 数据包 | 抽奖开始(小奖) |
| ReceiveDataPackageDebugEvent | 该事件用于调试, 收到任何 Data 数据包时都会触发 | |
| RoomAdminsPackageEvent | 收到 ROOM_ADMINS 数据包 | 房管变更 |
| RoomBlockMsgPackageEvent | 收到 ROOM_BLOCK_MSG 数据包 | 房间黑名单(房间管理员添加了一个用户到黑名单) |
| RoomLockPackageEvent | 收到 ROOM_LOCK 数据包 | 房间被封 |
| RoomRankPackageEvent | 收到 ROOM_RANK 数据包 | 小时榜 |
| RoomShieldPackageEvent | 收到 ROOM_SHIELD 数据包 | 房间屏蔽 |
| RoomSilentOffPackageEvent | 收到 ROOM_SILENT_OFF 数据包 | 房间结束禁言 |
| RoomSilentOnPackageEvent | 收到 ROOM_SILENT_ON 数据包 | 房间开启了禁言(禁止某一等级以下的用户发言) |
| SendGiftPackageEvent | 收到 SEND_GIFT 数据包 | 送礼 |
| SendHeartBeatPackageEvent | 每次发送心跳包后触发一次 | |
| SpecialGiftPackageEvent | 收到 SPECIAL_GIFT 数据包 | 节奏风暴(20 倍以下的)(只在对应房间内有, 不会全站广播) |
| SysGiftPackageEvent | 收到 SYS_GIFT 数据包 | 系统礼物(20 倍以上节奏风暴, 活动抽奖等) |
| SysMsgPackageEvent | 收到 SYS_MSG 数据包 | 系统消息(小电视等) |
| TVEndPackageEvent | 收到 TV_END 数据包 | 小电视抽奖结束(大奖的获得者信息) |
| TVStartPackageEvent | 收到 TV_START 数据包 | 小电视抽奖开始 |
| UnknownPackageEvent | B站新增了新种类的数据包, 出现此情况请提交 issue | |
| ViewerCountPackageEvent | 收到 房间人数 数据包(不是 Json) | |
| WelcomePackageEvent | 收到 WELCOME 数据包 | 欢迎(通常是 VIP) |
| WelcomeActivityPackageEvent | 收到 WELCOME_ACTIVITY 数据包 | 欢迎(活动) |
| WelcomeGuardPackageEvent | 收到 WELCOME_GUARD 数据包 | 欢迎(舰队) |
| WishBottlePackageEvent | 收到 WISH_BOTTLE 数据包 | 许愿瓶 |
事件里面可以取到解析好的 POJO, 然后可以从里面取数据, 见上面的监听器示例.

View File

@ -204,8 +204,8 @@ public interface LiveService {
/**
* 发送一条弹幕
*
* @param cid 房间号
* @param mid 自己的用户 ID
* @param roomId 房间号
* @param userId 自己的用户 ID
* @param message 内容
* @param random 随机数
* @param mode 弹幕模式
@ -218,8 +218,8 @@ public interface LiveService {
*/
@POST("api/sendmsg")
@FormUrlEncoded
Call<SendBulletScreenResponseEntity> sendBulletScreen(@Field("cid") long cid,
@Field("mid") long mid,
Call<SendBulletScreenResponseEntity> sendBulletScreen(@Field("cid") long roomId,
@Field("mid") long userId,
@Field("msg") String message,
@Field("rnd") long random,
@Field("mode") int mode,
@ -236,8 +236,8 @@ public interface LiveService {
*/
default Call<SendBulletScreenResponseEntity> sendBulletScreen(BulletScreenEntity bulletScreenEntity) {
return sendBulletScreen(
bulletScreenEntity.getCid(),
bulletScreenEntity.getMid(),
bulletScreenEntity.getRoomId(),
bulletScreenEntity.getUserId(),
bulletScreenEntity.getMessage(),
bulletScreenEntity.getRandom(),
bulletScreenEntity.getMode(),

View File

@ -54,7 +54,7 @@ public class ActivityGiftsEntity extends ResponseEntity {
@SerializedName("name")
private String name;
@SerializedName("num")
private int num;
private int number;
@SerializedName("img")
private String img;
@SerializedName("gift_url")
@ -92,12 +92,12 @@ public class ActivityGiftsEntity extends ResponseEntity {
this.name = name;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
public String getImg() {

View File

@ -1075,7 +1075,7 @@ public class AllListEntity extends ResponseEntity {
@SerializedName("face")
private String face;
@SerializedName("mid")
private int mid;
private long userId;
@SerializedName("name")
private String name;
@ -1087,12 +1087,12 @@ public class AllListEntity extends ResponseEntity {
this.face = face;
}
public int getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(int mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getName() {

View File

@ -69,7 +69,7 @@ public class AssistantRoomInfoEntity extends ResponseEntity {
@SerializedName("uname")
private String username;
@SerializedName("rcost")
private int rcost;
private int roomCost;
@SerializedName("online")
private int online;
@SerializedName("status")
@ -141,12 +141,12 @@ public class AssistantRoomInfoEntity extends ResponseEntity {
this.username = username;
}
public int getRcost() {
return rcost;
public int getRoomCost() {
return roomCost;
}
public void setRcost(int rcost) {
this.rcost = rcost;
public void setRoomCost(int roomCost) {
this.roomCost = roomCost;
}
public int getOnline() {

View File

@ -95,7 +95,7 @@ public class AwardsEntity extends ResponseEntity {
@SerializedName("id")
private int id;
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("gift_name")
private String giftName;
@SerializedName("gift_type")
@ -137,12 +137,12 @@ public class AwardsEntity extends ResponseEntity {
this.id = id;
}
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getGiftName() {

View File

@ -3,9 +3,11 @@ package com.hiczp.bilibili.api.live.entity;
import com.google.gson.annotations.SerializedName;
public class BulletScreenEntity {
private long cid;
@SerializedName("cid")
private long roomId;
private long mid;
@SerializedName("mid")
private long userId;
/**
* 弹幕长度限制为 LiveRoomInfoEntity.getData().getMsgLength(), 对于每个用户而言, 每个房间都一样
@ -50,27 +52,27 @@ public class BulletScreenEntity {
/**
* 实际上并不需要包含 mid 就可以正常发送弹幕, 但是真实的 Android 客户端确实发送了 mid
*/
public BulletScreenEntity(long cid, long mid, String message) {
this.cid = cid;
this.mid = mid;
public BulletScreenEntity(long roomId, long userId, String message) {
this.roomId = roomId;
this.userId = userId;
this.message = message;
}
public long getCid() {
return cid;
public long getRoomId() {
return roomId;
}
public BulletScreenEntity setCid(long cid) {
this.cid = cid;
public BulletScreenEntity setRoomId(long roomId) {
this.roomId = roomId;
return this;
}
public long getMid() {
return mid;
public long getUserId() {
return userId;
}
public BulletScreenEntity setMid(long mid) {
this.mid = mid;
public BulletScreenEntity setUserId(long userId) {
this.userId = userId;
return this;
}

View File

@ -45,7 +45,7 @@ public class GiftEntity {
}
public GiftEntity(long giftId, long bagId, long number, LiveRoomInfoEntity.LiveRoom liveRoom) {
this(giftId, bagId, number, liveRoom.getRoomId(), liveRoom.getMid());
this(giftId, bagId, number, liveRoom.getRoomId(), liveRoom.getUserId());
}
public GiftEntity(PlayerBagEntity.BagGift bagGift, long number, long roomId, long roomUserId) {
@ -53,7 +53,7 @@ public class GiftEntity {
}
public GiftEntity(PlayerBagEntity.BagGift bagGift, long number, LiveRoomInfoEntity.LiveRoom liveRoom) {
this(bagGift.getGiftId(), bagGift.getId(), number, liveRoom.getRoomId(), liveRoom.getMid());
this(bagGift.getGiftId(), bagGift.getId(), number, liveRoom.getRoomId(), liveRoom.getUserId());
}
public long getGiftId() {

View File

@ -105,7 +105,7 @@ public class GiftTopEntity extends ResponseEntity {
*/
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("rank")
private int rank;
@SerializedName("isSelf")
@ -121,12 +121,12 @@ public class GiftTopEntity extends ResponseEntity {
@SerializedName("guard_level")
private int guardLevel;
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public int getRank() {

View File

@ -77,7 +77,7 @@ public class LiveHistoryBulletScreensEntity extends ResponseEntity {
@SerializedName("text")
private String text;
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("nickname")
private String nickname;
@SerializedName("timeline")
@ -113,12 +113,12 @@ public class LiveHistoryBulletScreensEntity extends ResponseEntity {
this.text = text;
}
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getNickname() {

View File

@ -96,13 +96,13 @@ public class LiveRoomInfoEntity extends ResponseEntity {
@SerializedName("cover")
private String cover;
@SerializedName("mid")
private long mid;
private long userId;
@SerializedName("uname")
private String username;
@SerializedName("face")
private String face;
@SerializedName("m_face")
private String mFace;
private String mobileFace;
@SerializedName("background_id")
private int backgroundId;
@SerializedName("attention")
@ -116,7 +116,7 @@ public class LiveRoomInfoEntity extends ResponseEntity {
@SerializedName("create_at")
private String createAt;
@SerializedName("sch_id")
private int schId;
private int scheduleId;
@SerializedName("status")
private String status;
@SerializedName("area")
@ -218,12 +218,12 @@ public class LiveRoomInfoEntity extends ResponseEntity {
this.cover = cover;
}
public long getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(long mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getUsername() {
@ -242,12 +242,12 @@ public class LiveRoomInfoEntity extends ResponseEntity {
this.face = face;
}
public String getMFace() {
return mFace;
public String getMobileFace() {
return mobileFace;
}
public void setMFace(String mFace) {
this.mFace = mFace;
public void setMobileFace(String mobileFace) {
this.mobileFace = mobileFace;
}
public int getBackgroundId() {
@ -298,12 +298,12 @@ public class LiveRoomInfoEntity extends ResponseEntity {
this.createAt = createAt;
}
public int getSchId() {
return schId;
public int getScheduleId() {
return scheduleId;
}
public void setSchId(int schId) {
this.schId = schId;
public void setScheduleId(int scheduleId) {
this.scheduleId = scheduleId;
}
public String getStatus() {
@ -630,11 +630,11 @@ public class LiveRoomInfoEntity extends ResponseEntity {
@SerializedName("cid")
private long cid;
@SerializedName("sch_id")
private int schId;
private int scheduleId;
@SerializedName("title")
private String title;
@SerializedName("mid")
private long mid;
private long userId;
@SerializedName("start")
private long start;
@SerializedName("start_at")
@ -662,12 +662,12 @@ public class LiveRoomInfoEntity extends ResponseEntity {
this.cid = cid;
}
public int getSchId() {
return schId;
public int getScheduleId() {
return scheduleId;
}
public void setSchId(int schId) {
this.schId = schId;
public void setScheduleId(int scheduleId) {
this.scheduleId = scheduleId;
}
public String getTitle() {
@ -678,12 +678,12 @@ public class LiveRoomInfoEntity extends ResponseEntity {
this.title = title;
}
public long getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(long mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public long getStart() {
@ -941,7 +941,7 @@ public class LiveRoomInfoEntity extends ResponseEntity {
@SerializedName("face")
private String face;
@SerializedName("mid")
private int mid;
private long userId;
@SerializedName("name")
private String name;
@ -953,12 +953,12 @@ public class LiveRoomInfoEntity extends ResponseEntity {
this.face = face;
}
public int getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(int mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getName() {

View File

@ -59,7 +59,7 @@ public class MyTitleListEntity extends ResponseEntity {
*/
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("had")
private boolean had;
@SerializedName("title")
@ -77,12 +77,12 @@ public class MyTitleListEntity extends ResponseEntity {
@SerializedName("category")
private List<Category> category;
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public boolean isHad() {

View File

@ -130,7 +130,7 @@ public class OpenCapsuleResponseEntity extends ResponseEntity {
@SerializedName("name")
private String name;
@SerializedName("num")
private String num;
private String number;
@SerializedName("img")
private String img;
@ -142,12 +142,12 @@ public class OpenCapsuleResponseEntity extends ResponseEntity {
this.name = name;
}
public String getNum() {
return num;
public String getNumber() {
return number;
}
public void setNum(String num) {
this.num = num;
public void setNumber(String number) {
this.number = number;
}
public String getImg() {

View File

@ -53,7 +53,7 @@ public class PlayerBagEntity extends ResponseEntity {
@SerializedName("id")
private long id;
@SerializedName("uid")
private long uid;
private long userId;
@SerializedName("gift_id")
private long giftId;
@SerializedName("gift_num")
@ -85,12 +85,12 @@ public class PlayerBagEntity extends ResponseEntity {
this.id = id;
}
public long getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(long uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public long getGiftId() {

View File

@ -578,7 +578,7 @@ public class RecommendRoomRefreshResponseEntity extends ResponseEntity {
@SerializedName("face")
private String face;
@SerializedName("mid")
private int mid;
private long userId;
@SerializedName("name")
private String name;
@ -590,12 +590,12 @@ public class RecommendRoomRefreshResponseEntity extends ResponseEntity {
this.face = face;
}
public int getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(int mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getName() {

View File

@ -125,7 +125,7 @@ public class SendGiftResponseEntity extends ResponseEntity {
@SerializedName("uname")
private String username;
@SerializedName("rcost")
private int rcost;
private int roomCost;
@SerializedName("uid")
private int uid;
@SerializedName("timestamp")
@ -206,12 +206,12 @@ public class SendGiftResponseEntity extends ResponseEntity {
this.username = username;
}
public int getRcost() {
return rcost;
public int getRoomCost() {
return roomCost;
}
public void setRcost(int rcost) {
this.rcost = rcost;
public void setRoomCost(int roomCost) {
this.roomCost = roomCost;
}
public int getUid() {

View File

@ -171,7 +171,7 @@ public class UserTasksEntity extends ResponseEntity {
@SerializedName("type")
private String type;
@SerializedName("num")
private int num;
private int number;
public String getName() {
return name;
@ -189,12 +189,12 @@ public class UserTasksEntity extends ResponseEntity {
this.type = type;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
}
}
@ -288,7 +288,7 @@ public class UserTasksEntity extends ResponseEntity {
@SerializedName("type")
private String type;
@SerializedName("num")
private int num;
private int number;
public String getName() {
return name;
@ -306,12 +306,12 @@ public class UserTasksEntity extends ResponseEntity {
this.type = type;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
}
}
@ -427,7 +427,7 @@ public class UserTasksEntity extends ResponseEntity {
@SerializedName("type")
private String type;
@SerializedName("num")
private int num;
private int number;
public String getName() {
return name;
@ -445,12 +445,12 @@ public class UserTasksEntity extends ResponseEntity {
this.type = type;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
}
}

View File

@ -58,7 +58,7 @@ public class WearTitleEntity extends ResponseEntity {
@SerializedName("tid")
private String tid;
@SerializedName("num")
private String num;
private String number;
@SerializedName("score")
private String score;
@SerializedName("create_time")
@ -104,12 +104,12 @@ public class WearTitleEntity extends ResponseEntity {
this.tid = tid;
}
public String getNum() {
return num;
public String getNumber() {
return number;
}
public void setNum(String num) {
this.num = num;
public void setNumber(String number) {
this.number = number;
}
public String getScore() {

View File

@ -38,9 +38,9 @@ public class LiveClient {
private final BilibiliServiceProvider bilibiliServiceProvider;
private final EventLoopGroup eventLoopGroup;
private final long userId;
private final EventBus eventBus = new EventBus("BilibiliLiveClientEventBus");
private Long showRoomId;
private Long realRoomId;
private final EventBus eventBus;
private boolean useRealRoomIdForConstructing;
private LiveRoomInfoEntity.LiveRoom liveRoom;
@ -57,6 +57,7 @@ public class LiveClient {
showRoomId = roomId;
}
this.userId = userId;
this.eventBus = new EventBus(String.format("BilibiliLiveClientEventBus-%s", getShowRoomIdOrRoomId()));
}
public LiveClient(@Nonnull BilibiliServiceProvider bilibiliServiceProvider, @Nonnull EventLoopGroup eventLoopGroup, long showRoomId, long userId) {

View File

@ -50,20 +50,20 @@ public class GuardBuyEntity implements DataEntity {
*/
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("username")
private String username;
@SerializedName("guard_level")
private int guardLevel;
@SerializedName("num")
private int num;
private int number;
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getUsername() {
@ -82,12 +82,12 @@ public class GuardBuyEntity implements DataEntity {
this.guardLevel = guardLevel;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
}
}

View File

@ -72,7 +72,7 @@ public class PkProcessEntity implements DataEntity {
*/
@SerializedName("uid")
private int userId;
private long userId;
@SerializedName("init_votes")
private int initVotes;
@SerializedName("match_votes")
@ -80,11 +80,11 @@ public class PkProcessEntity implements DataEntity {
@SerializedName("user_votes")
private int userVotes;
public int getUserId() {
public long getUserId() {
return userId;
}
public void setUserId(int userId) {
public void setUserId(long userId) {
this.userId = userId;
}

View File

@ -13,7 +13,7 @@ public class RoomBlockMsgEntity implements DataEntity {
@SerializedName("cmd")
private String cmd;
@SerializedName("uid")
private String uid;
private String userId;
@SerializedName("uname")
private String username;
@SerializedName("roomid")
@ -28,12 +28,12 @@ public class RoomBlockMsgEntity implements DataEntity {
this.cmd = cmd;
}
public String getUid() {
return uid;
public String getUserId() {
return userId;
}
public void setUid(String uid) {
this.uid = uid;
public void setUserId(String userId) {
this.userId = userId;
}
public String getUsername() {

View File

@ -73,13 +73,13 @@ public class SendGiftEntity implements DataEntity {
@SerializedName("giftName")
private String giftName;
@SerializedName("num")
private int num;
private int number;
@SerializedName("uname")
private String username;
@SerializedName("rcost")
private int rcost;
private int roomCost;
@SerializedName("uid")
private long uid;
private long userId;
@SerializedName("timestamp")
private long timestamp;
@SerializedName("giftId")
@ -156,12 +156,12 @@ public class SendGiftEntity implements DataEntity {
this.giftName = giftName;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
public String getUsername() {
@ -172,20 +172,20 @@ public class SendGiftEntity implements DataEntity {
this.username = username;
}
public int getRcost() {
return rcost;
public int getRoomCost() {
return roomCost;
}
public void setRcost(int rcost) {
this.rcost = rcost;
public void setRoomCost(int roomCost) {
this.roomCost = roomCost;
}
public long getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(long uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public long getTimestamp() {
@ -477,7 +477,7 @@ public class SendGiftEntity implements DataEntity {
@SerializedName("hadJoin")
private int hadJoin;
@SerializedName("num")
private int num;
private int number;
@SerializedName("content")
private String content;
@SerializedName("action")
@ -509,12 +509,12 @@ public class SendGiftEntity implements DataEntity {
this.hadJoin = hadJoin;
}
public int getNum() {
return num;
public int getNumber() {
return number;
}
public void setNum(int num) {
this.num = num;
public void setNumber(int number) {
this.number = number;
}
public String getContent() {
@ -727,7 +727,7 @@ public class SendGiftEntity implements DataEntity {
*/
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("uname")
private String username;
@SerializedName("face")
@ -741,12 +741,12 @@ public class SendGiftEntity implements DataEntity {
@SerializedName("isSelf")
private int isSelf;
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getUsername() {

View File

@ -39,7 +39,7 @@ public class WelcomeActivityEntity implements DataEntity {
*/
@SerializedName("uid")
private long uid;
private long userId;
@SerializedName("uname")
private String username;
@SerializedName("type")
@ -47,12 +47,12 @@ public class WelcomeActivityEntity implements DataEntity {
@SerializedName("display_mode")
private int displayMode;
public long getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(long uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getUsername() {

View File

@ -50,7 +50,7 @@ public class WelcomeGuardEntity implements DataEntity {
*/
@SerializedName("uid")
private int uid;
private long userId;
@SerializedName("username")
private String username;
@SerializedName("guard_level")
@ -58,12 +58,12 @@ public class WelcomeGuardEntity implements DataEntity {
@SerializedName("water_god")
private Integer waterGod;
public int getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(int uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getUsername() {

View File

@ -87,7 +87,7 @@ public class WishBottleEntity implements DataEntity {
@SerializedName("id")
private long id;
@SerializedName("uid")
private long uid;
private long userId;
@SerializedName("type")
private int type;
@SerializedName("type_id")
@ -113,12 +113,12 @@ public class WishBottleEntity implements DataEntity {
this.id = id;
}
public long getUid() {
return uid;
public long getUserId() {
return userId;
}
public void setUid(long uid) {
this.uid = uid;
public void setUserId(long userId) {
this.userId = userId;
}
public int getType() {

View File

@ -19,6 +19,8 @@ import java.io.InputStreamReader;
import java.lang.reflect.ParameterizedType;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
@ -26,6 +28,56 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
private static final Gson GSON = new Gson();
private static final Gson PRETTY_PRINTING_GSON = new GsonBuilder().setPrettyPrinting().create();
private static final JsonParser JSON_PARSER = new JsonParser();
private static final Object[] CMD_AND_EVENT_ARRAY = new Object[]{
"ACTIVITY_EVENT", ActivityEventPackageEvent.class, //活动事件
"CHANGE_ROOM_INFO", ChangeRoomInfoPackageEvent.class, //更换房间背景图片
"COMBO_END", ComboEndPackageEvent.class, //COMBO
"COMBO_SEND", ComboSendPackageEvent.class,
"CUT_OFF", CutOffPackageEvent.class, // B站 管理员强制中断
"DANMU_MSG", DanMuMsgPackageEvent.class, //弹幕消息
"ENTRY_EFFECT", EntryEffectPackageEvent.class, //TODO 尚不明确 EntryEffect 和普通 Welcome 的区别
"EVENT_CMD", EventCmdPackageEvent.class, //TODO 尚不明确 EVENT_CMD 的含义
"GUARD_BUY", GuardBuyPackageEvent.class, //船票购买
"GUARD_MSG", GuardMsgPackageEvent.class, //舰队消息(登船)
"LIVE", LivePackageEvent.class, //开始直播
"PK_AGAIN", PkAgainPackageEvent.class, //PK
"PK_CLICK_AGAIN", PkClickAgainPackageEvent.class,
"PK_END", PkEndPackageEvent.class,
"PK_MATCH", PkMatchPackageEvent.class,
"PK_MIC_END", PkMicEndPackageEvent.class,
"PK_PRE", PkPrePackageEvent.class,
"PK_PROCESS", PkProcessPackageEvent.class,
"PK_SETTLE", PkSettlePackageEvent.class,
"PK_START", PkStartPackageEvent.class,
"PREPARING", PreparingPackageEvent.class, //停止直播
"RAFFLE_END", RaffleEndPackageEvent.class, //抽奖结束
"RAFFLE_START", RaffleStartPackageEvent.class, //抽奖开始(小奖, 通常是不定期活动)
"ROOM_ADMINS", RoomAdminsPackageEvent.class, //房管变更
"ROOM_BLOCK_MSG", RoomBlockMsgPackageEvent.class, //房间黑名单(房间管理员添加了一个用户到黑名单)
"ROOM_LOCK", RoomLockPackageEvent.class, //房间被封
"ROOM_RANK", RoomRankPackageEvent.class, //小时榜
"ROOM_SHIELD", RoomShieldPackageEvent.class, //房间屏蔽
"ROOM_SILENT_OFF", RoomSilentOffPackageEvent.class, //房间结束禁言
"ROOM_SILENT_ON", RoomSilentOnPackageEvent.class, //房间开启了禁言(禁止某一等级以下的用户发言)
"SEND_GIFT", SendGiftPackageEvent.class, //送礼
"SPECIAL_GIFT", SpecialGiftPackageEvent.class, //节奏风暴(20 倍以下的)
"SYS_GIFT", SysGiftPackageEvent.class, //系统礼物(节奏风暴, 活动抽奖等)
"SYS_MSG", SysMsgPackageEvent.class, //系统消息(小电视等)
"TV_END", TVEndPackageEvent.class, //小电视抽奖结束(大奖的获得者信息)
"TV_START", TVStartPackageEvent.class, //小电视抽奖开始
"WELCOME", WelcomePackageEvent.class, //欢迎(通常是 VIP)
"WELCOME_ACTIVITY", WelcomeActivityPackageEvent.class, //欢迎(活动)
"WELCOME_GUARD", WelcomeGuardPackageEvent.class, //欢迎(舰队)
"WISH_BOTTLE", WishBottlePackageEvent.class //许愿瓶
};
private static final Map<String, Class<? extends ReceiveDataPackageEvent>> EVENT_MAP = new HashMap<>();
static {
for (int i = 0; i < CMD_AND_EVENT_ARRAY.length; i += 2) {
//noinspection unchecked
EVENT_MAP.put((String) CMD_AND_EVENT_ARRAY[i], (Class<? extends ReceiveDataPackageEvent>) CMD_AND_EVENT_ARRAY[i + 1]);
}
}
private final LiveClient liveClient;
private final EventBus eventBus;
@ -79,201 +131,9 @@ public class LiveClientHandler extends SimpleChannelInboundHandler<Package> {
e.printStackTrace();
break;
}
eventBus.post(new ReceiveDataPackageDebugEvent(liveClient, jsonObject, cmd));
Class<? extends ReceiveDataPackageEvent> eventType = null;
switch (cmd) {
//弹幕消息
case "DANMU_MSG": {
eventType = DanMuMsgPackageEvent.class;
}
break;
//送礼
case "SEND_GIFT": {
eventType = SendGiftPackageEvent.class;
}
break;
//combo
case "COMBO_SEND": {
eventType = ComboSendPackageEvent.class;
}
break;
case "COMBO_END": {
eventType = ComboEndPackageEvent.class;
}
break;
//欢迎
case "WELCOME": {
eventType = WelcomePackageEvent.class;
}
break;
//许愿瓶
case "WISH_BOTTLE": {
eventType = WishBottlePackageEvent.class;
}
break;
//欢迎(舰队)
case "WELCOME_GUARD": {
eventType = WelcomeGuardPackageEvent.class;
}
break;
//TODO 尚不明确 EntryEffect 和普通 Welcome 的区别
case "ENTRY_EFFECT": {
eventType = EntryEffectPackageEvent.class;
}
break;
//PK
case "PK_MATCH": {
eventType = PkMatchPackageEvent.class;
}
break;
case "PK_PRE": {
eventType = PkPrePackageEvent.class;
}
break;
case "PK_START": {
eventType = PkStartPackageEvent.class;
}
break;
case "PK_PROCESS": {
eventType = PkProcessPackageEvent.class;
}
break;
case "PK_END": {
eventType = PkEndPackageEvent.class;
}
break;
case "PK_MIC_END": {
eventType = PkMicEndPackageEvent.class;
}
break;
case "PK_SETTLE": {
eventType = PkSettlePackageEvent.class;
}
break;
case "PK_AGAIN": {
eventType = PkAgainPackageEvent.class;
}
break;
case "PK_CLICK_AGAIN": {
eventType = PkClickAgainPackageEvent.class;
}
break;
//系统消息(小电视等)
case "SYS_MSG": {
eventType = SysMsgPackageEvent.class;
}
break;
//系统礼物(节奏风暴, 活动抽奖等)
case "SYS_GIFT": {
eventType = SysGiftPackageEvent.class;
}
break;
//活动事件
case "ACTIVITY_EVENT": {
eventType = ActivityEventPackageEvent.class;
}
break;
//节奏风暴(20 倍以下的)
case "SPECIAL_GIFT": {
eventType = SpecialGiftPackageEvent.class;
}
break;
//抽奖开始(小奖, 通常是不定期活动)
case "RAFFLE_START": {
eventType = RaffleStartPackageEvent.class;
}
break;
//抽奖结束
case "RAFFLE_END": {
eventType = RaffleEndPackageEvent.class;
}
break;
//TODO 尚不明确 EVENT_CMD 的含义
case "EVENT_CMD": {
eventType = EventCmdPackageEvent.class;
}
break;
//房间黑名单(房间管理员添加了一个用户到黑名单)
case "ROOM_BLOCK_MSG": {
eventType = RoomBlockMsgPackageEvent.class;
}
break;
//房间开启了禁言(禁止某一等级以下的用户发言)
case "ROOM_SILENT_ON": {
eventType = RoomSilentOnPackageEvent.class;
}
break;
//房间结束禁言
case "ROOM_SILENT_OFF": {
eventType = RoomSilentOffPackageEvent.class;
}
break;
//船票购买
case "GUARD_BUY": {
eventType = GuardBuyPackageEvent.class;
}
break;
//舰队消息(登船)
case "GUARD_MSG": {
eventType = GuardMsgPackageEvent.class;
}
break;
//小电视抽奖开始
case "TV_START": {
eventType = TVStartPackageEvent.class;
}
break;
//小电视抽奖结束(大奖的获得者信息)
case "TV_END": {
eventType = TVEndPackageEvent.class;
}
break;
//小时榜
case "ROOM_RANK": {
eventType = RoomRankPackageEvent.class;
}
break;
//欢迎(活动)
case "WELCOME_ACTIVITY": {
eventType = WelcomeActivityPackageEvent.class;
}
break;
//房管变更
case "ROOM_ADMINS": {
eventType = RoomAdminsPackageEvent.class;
}
break;
//开始直播
case "LIVE": {
eventType = LivePackageEvent.class;
}
break;
//停止直播
case "PREPARING": {
eventType = PreparingPackageEvent.class;
}
break;
//房间屏蔽
case "ROOM_SHIELD": {
eventType = RoomShieldPackageEvent.class;
}
break;
//更换房间背景图片
case "CHANGE_ROOM_INFO": {
eventType = ChangeRoomInfoPackageEvent.class;
}
break;
// B站 管理员强制中断
case "CUT_OFF": {
eventType = CutOffPackageEvent.class;
}
break;
//房间被封
case "ROOM_LOCK": {
eventType = RoomLockPackageEvent.class;
}
break;
}
eventBus.post(new ReceiveDataPackageDebugEvent(liveClient, jsonObject, cmd)); //debug
Class<? extends ReceiveDataPackageEvent> eventType = EVENT_MAP.get(cmd);
//UnknownPackage
if (eventType == null) {

View File

@ -51,7 +51,7 @@ public class InfoEntity extends ResponseEntity {
*/
@SerializedName("mid")
private long mid;
private long userId;
@SerializedName("appid")
private int appId;
@SerializedName("access_token")
@ -59,16 +59,16 @@ public class InfoEntity extends ResponseEntity {
@SerializedName("expires_in")
private long expiresIn;
@SerializedName("userid")
private String userId;
private String userIdString;
@SerializedName("uname")
private String username;
public long getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(long mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public int getAppId() {
@ -95,12 +95,12 @@ public class InfoEntity extends ResponseEntity {
this.expiresIn = expiresIn;
}
public String getUserId() {
return userId;
public String getUserIdString() {
return userIdString;
}
public void setUserId(String userId) {
this.userId = userId;
public void setUserIdString(String userIdString) {
this.userIdString = userIdString;
}
public String getUsername() {

View File

@ -45,7 +45,7 @@ public class LoginResponseEntity extends ResponseEntity {
return new BilibiliAccount(
this.data.accessToken,
this.data.refreshToken,
this.data.mid,
this.data.userId,
this.data.expiresIn,
this.timestamp
);
@ -64,7 +64,7 @@ public class LoginResponseEntity extends ResponseEntity {
@SerializedName("refresh_token")
private String refreshToken;
@SerializedName("mid")
private long mid;
private long userId;
@SerializedName("expires_in")
private long expiresIn;
@ -84,12 +84,12 @@ public class LoginResponseEntity extends ResponseEntity {
this.refreshToken = refreshToken;
}
public long getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(long mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public long getExpiresIn() {

View File

@ -45,7 +45,7 @@ public class RefreshTokenResponseEntity extends ResponseEntity {
return new BilibiliAccount(
this.data.accessToken,
this.data.refreshToken,
this.data.mid,
this.data.userId,
this.data.expiresIn,
this.ts
);
@ -60,7 +60,7 @@ public class RefreshTokenResponseEntity extends ResponseEntity {
*/
@SerializedName("mid")
private long mid;
private long userId;
@SerializedName("refresh_token")
private String refreshToken;
@SerializedName("access_token")
@ -68,12 +68,12 @@ public class RefreshTokenResponseEntity extends ResponseEntity {
@SerializedName("expires_in")
private long expiresIn;
public long getMid() {
return mid;
public long getUserId() {
return userId;
}
public void setMid(long mid) {
this.mid = mid;
public void setUserId(long userId) {
this.userId = userId;
}
public String getRefreshToken() {

View File

@ -8,7 +8,7 @@ public class Config {
private String username;
private String password;
private int roomId;
private long roomId;
static Config getInstance() {
return config;
@ -34,11 +34,11 @@ public class Config {
this.password = password;
}
int getRoomId() {
long getRoomId() {
return roomId;
}
public void setRoomId(int roomId) {
public void setRoomId(long roomId) {
this.roomId = roomId;
}

View File

@ -130,7 +130,7 @@ public class LiveClientTest {
LOGGER.info("[SendGift] {} give {}*{}",
data.getUsername(),
data.getGiftName(),
data.getNum()
data.getNumber()
);
}