Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbjcbjc committed May 9, 2022
1 parent 95f2b26 commit ef77ca2
Show file tree
Hide file tree
Showing 342 changed files with 6,914 additions and 2,917 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import com.game.enums.UserStatus;
import com.game.manager.RoomManager;
import com.game.proto.Message.FrameHandle;
import com.game.proto.Message.RepairFrame;
import com.game.proto.C2BNet.FrameHandle;
import com.game.proto.C2BNet.RepairFrame;
//import com.game.proto.Message.FrameHandle;
//import com.game.proto.Message.RepairFrame;
import com.game.thread.BattleRoomThread;
import com.game.util.CachedThreadPoolUtil;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.backblaze.erasure.fec.Snmp;

import com.game.manager.ConnectionManagerKCP;
import com.game.proto.Message;
//import com.game.proto.Message;
import com.game.proto.C2BNet;
import com.google.protobuf.InvalidProtocolBufferException;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
Expand All @@ -29,7 +30,6 @@ public void onConnected(Ukcp ukcp) {

@Override
public void handleReceive(ByteBuf buf, Ukcp kcp) {

final byte[] array;
final int offset;
final int length = buf.readableBytes();
Expand All @@ -46,31 +46,9 @@ public void handleReceive(ByteBuf buf, Ukcp kcp) {
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
assert nm != null;
System.out.println(nm.getMessageType());
// System.out.println(nm);




/*final byte[] array;
final int offset;
final int length = buf.readableBytes();
if (buf.hasArray()) {
array = buf.array();
offset = buf.arrayOffset() + buf.readerIndex();
} else {
array = ByteBufUtil.getBytes(buf, buf.readerIndex(), length, false);
offset = 0;
}
Message.NetMessageRequest2 nm = null;
try {
nm = Message.NetMessageRequest2.getDefaultInstance().getParserForType().parseFrom(array, offset, length);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
// System.out.println(nm);
MessageDispatch.Instance.DispatchData(kcp,nm);*/
assert nm != null;
MessageDispatch.Instance.DispatchData(kcp,nm.getRequest());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.game.manager.ConnectionManager;

import com.game.network.MessageDispatch;
import com.game.proto.Message;
//import com.game.proto.Message;
import com.game.proto.C2BNet;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
Expand Down Expand Up @@ -55,9 +56,9 @@ protected void channelRead0(ChannelHandlerContext ctx, BinaryWebSocketFrame fram
array = ByteBufUtil.getBytes(msg, msg.readerIndex(), length, false);
offset = 0;
}
Message.NetMessageRequest2 nm = Message.NetMessageRequest2.getDefaultInstance().getParserForType().parseFrom(array, offset, length);
C2BNet.C2BNetMessage nm = C2BNet.C2BNetMessage.getDefaultInstance().getParserForType().parseFrom(array, offset, length);
// System.out.println(nm);
MessageDispatch.Instance.DispatchData(ctx, nm);
MessageDispatch.Instance.DispatchData(ctx, nm.getRequest());
}

/*@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.game.manager.ConnectionManagerKCP;
import com.game.manager.UserManager;
import com.game.models.User;
import com.game.proto.Message;
import com.game.proto.Message.*;
//import com.game.proto.Message;
//import com.game.proto.Message.*;
import com.game.proto.C2BNet;
import com.game.service.*;
import com.game.spring.SpringBeanUtil;

Expand All @@ -23,11 +24,11 @@ public MessageDispatch() {

public static MessageDispatch Instance=new MessageDispatch();

public void DispatchData(ChannelHandlerContext ctx, NetMessageRequest2 message) {
public void DispatchData(ChannelHandlerContext ctx, C2BNet.C2BNetMessageRequest message) {


}
public void DispatchData(Ukcp kcp, Message.NetMessageRequest2 message) {
public void DispatchData(Ukcp kcp, C2BNet.C2BNetMessageRequest message) {
int userId=message.getUserId();
User battleUser=userManager.getuser(userId) ; //对战用户
User liveUser=userManager.getliveuser(userId) ; //直播用户
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import com.backblaze.erasure.FecAdapt;
import com.backblaze.erasure.fec.Snmp;
import com.game.models.User;
import com.game.proto.Message;
//import com.game.proto.Message;
import com.game.proto.C2BNet;
import com.google.protobuf.MessageLite;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
Expand All @@ -26,11 +27,11 @@ public NetConnectionKCP(User user, Ukcp kcp) {
this.user=user;
}

private Message.NetMessageResponse2.Builder message;
private C2BNet.C2BNetMessageResponse.Builder message;

public Message.NetMessageResponse2.Builder getResponse() {
public C2BNet.C2BNetMessageResponse.Builder getResponse() {
if (message == null) {
message = Message.NetMessageResponse2.newBuilder();
message = C2BNet.C2BNetMessageResponse.newBuilder();
}
return message;
}
Expand All @@ -39,7 +40,7 @@ public Message.NetMessageResponse2.Builder getResponse() {
* 发送帧操作
* @param message2
*/
public void sendFrameHandleRes(Message.NetMessageResponse2.Builder message2) {
public void sendFrameHandleRes(C2BNet.C2BNetMessageResponse.Builder message2) {
if(message != null) { //合并包
message.setFrameHandleRes(message2.getFrameHandleRes());
this.send();
Expand All @@ -52,7 +53,7 @@ public void sendFrameHandleRes(Message.NetMessageResponse2.Builder message2) {
* 发送直播帧操作
* @param message2
*/
public void sendLiveFrameRes(Message.NetMessageResponse2.Builder message2) {
public void sendLiveFrameRes(C2BNet.C2BNetMessageResponse.Builder message2) {
if(message != null) { //合并包
message.setLiveFrameRes(message2.getLiveFrameRes());
this.send();
Expand All @@ -69,7 +70,7 @@ public void send() {
}


public void send(Message.NetMessageResponse2.Builder message2) {
public void send(C2BNet.C2BNetMessageResponse.Builder message2) {
this.kcp.write(Unpooled.wrappedBuffer(message2.build().toByteArray()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.game.network.NetConnectionKCP;
import com.game.network.NetConnectionWebSocket;

import com.game.proto.Message.FrameHandle;
import com.game.proto.Message.GameOverRequest;
import com.game.proto.Message.PercentForward;
import com.game.proto.Message.RepairFrameRequest;
import com.game.proto.C2BNet.FrameHandle;
import com.game.proto.C2BNet.GameOverRequest;
import com.game.proto.C2BNet.PercentForward;
import com.game.proto.C2BNet.RepairFrameRequest;
//import com.game.proto.Message.FrameHandle;
//import com.game.proto.Message.GameOverRequest;
//import com.game.proto.Message.PercentForward;
//import com.game.proto.Message.RepairFrameRequest;

public interface BattleService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
import com.game.manager.RoomManager;
import com.game.models.Room;
import com.game.models.User;
import com.game.proto.Message.FrameHandle;
import com.game.proto.Message.GameOverRequest;
import com.game.proto.Message.NetMessageResponse2;
import com.game.proto.Message.PercentForward;
import com.game.proto.Message.PercentForwardResponse;
import com.game.proto.Message.RepairFrame;
import com.game.proto.Message.RepairFrameRequest;
import com.game.proto.Message.RepairFrameResponse;
import com.game.proto.C2BNet.FrameHandle;
import com.game.proto.C2BNet.GameOverRequest;
import com.game.proto.C2BNet.C2BNetMessageResponse;
import com.game.proto.C2BNet.PercentForward;
import com.game.proto.C2BNet.PercentForwardResponse;
import com.game.proto.C2BNet.RepairFrame;
import com.game.proto.C2BNet.RepairFrameRequest;
import com.game.proto.C2BNet.RepairFrameResponse;
//import com.game.proto.Message.FrameHandle;
//import com.game.proto.Message.GameOverRequest;
//import com.game.proto.Message.NetMessageResponse2;
//import com.game.proto.Message.PercentForward;
//import com.game.proto.Message.PercentForwardResponse;
//import com.game.proto.Message.RepairFrame;
//import com.game.proto.Message.RepairFrameRequest;
//import com.game.proto.Message.RepairFrameResponse;
import com.game.service.BattleService;

@Service
Expand Down Expand Up @@ -59,7 +67,7 @@ public void OnPercentForward(NetConnectionKCP connection, PercentForward percent
percentForwardBuilder.setPercentForward(percentForward);
percentForwardBuilder.setAllUserLoadSucess(room.ValidateAllUserLoadSucess());

NetMessageResponse2.Builder response=NetMessageResponse2.newBuilder();
C2BNetMessageResponse.Builder response=C2BNetMessageResponse.newBuilder();
response.setPercentForwardRes(percentForwardBuilder);

for (User u : room.users) {
Expand Down Expand Up @@ -102,7 +110,7 @@ public void OnRepairFrame(NetConnectionKCP conn, RepairFrameRequest repairFrameR

RepairFrameResponse.Builder repairFrameResponseBuilder=RepairFrameResponse.newBuilder();
repairFrameResponseBuilder.addAllRepairFrames(rangeFrameList);
NetMessageResponse2.Builder response=conn.getResponse();
C2BNetMessageResponse.Builder response=conn.getResponse();
response.setRepairFrameRes(repairFrameResponseBuilder);
// conn.send();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import com.game.models.Room;
import com.game.models.User;
import com.game.network.NetConnectionKCP;
import com.game.proto.Message.LiveFrameResponse;
import com.game.proto.Message.NetMessageResponse2;
import com.game.proto.Message.RepairFrame;
import com.game.proto.C2BNet.LiveFrameResponse;
import com.game.proto.C2BNet.C2BNetMessageResponse;
import com.game.proto.C2BNet.RepairFrame;
//import com.game.proto.Message.LiveFrameResponse;
//import com.game.proto.Message.NetMessageResponse2;
//import com.game.proto.Message.RepairFrame;
import com.game.proto.Message.RepairFrameResponse;
import com.game.util.Config;

Expand All @@ -34,7 +37,7 @@ public class BattleRoomLiveThread extends Thread{
public int sleepTime = Config.LiveIntervalForwardTime*1000; //休眠时间

private LiveFrameResponse.Builder liveFrameResponseBuilder=LiveFrameResponse.newBuilder();
private NetMessageResponse2.Builder response=NetMessageResponse2.newBuilder();
private C2BNetMessageResponse.Builder response=C2BNetMessageResponse.newBuilder();
private List<RepairFrame> rangeFrameList=new ArrayList<>();

public BattleRoomLiveThread(Room room) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import com.game.models.Room;
import com.game.models.User;
import com.game.network.NetConnectionWebSocket;
import com.game.proto.Message.FrameHandle;
import com.game.proto.Message.FrameHandleResponse;
import com.game.proto.Message.NetMessageResponse2;
import com.game.proto.C2BNet.FrameHandle;
import com.game.proto.C2BNet.FrameHandleResponse;
import com.game.proto.C2BNet.C2BNetMessageResponse;
//import com.game.proto.Message.FrameHandle;
//import com.game.proto.Message.FrameHandleResponse;
//import com.game.proto.Message.NetMessageResponse2;
import com.game.util.CachedThreadPoolUtil;
import com.game.util.Config;

Expand All @@ -35,7 +38,7 @@ public class BattleRoomThread extends Thread{
private Room room;
private FrameHandleResponse.Builder frameHandleResponseBuilder=FrameHandleResponse.newBuilder();
private Collection<FrameHandle> frameHandleList=new ArrayList<>();
private NetMessageResponse2.Builder response = NetMessageResponse2.newBuilder();
private C2BNetMessageResponse.Builder response = C2BNetMessageResponse.newBuilder();
Map<Integer, FrameHandle> userFrameHandleMap = new HashMap<Integer, FrameHandle>();

public BattleRoomThread(Room room) {
Expand Down
Binary file modified Src/Server/BattleServer/target/classes/com/game/models/Room.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 2 additions & 22 deletions Src/Server/GameServer/src/main/java/com/game/entity/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import com.game.proto.Message.AttrPromoteType;
import com.game.proto.Message.NCharacter;
import com.game.proto.C2GNet.NCharacter;
import com.game.spring.DBUtil;
/**
* @author 贾超博
Expand Down Expand Up @@ -52,27 +52,7 @@ public Character(int cId, Integer userId) {
public NCharacter getCharacterInfo() {

return NCharacter.newBuilder()
.setTid(id)
.setCid(cId)
.setLevel(level)
.setExp(exp)
.setUserId(userId)
.setAttSpot(attSpot)
.setAtt((int)att)
.setDefSpot(defSpot)
.setDef((int)def)
.setHpSpot(hpSpot)
.setHp((int)hp)
.setCriSpot(criSpot)
.setCri((int)cri)
.setResuSpot(resuSpot)
.setResu((int)resu)
.setSpeedSpot(speedSpot)
.setSpeed((int)speed)
.setSpeedValue((int)speedValue)
.setCdSpot(cdSpot)
.setCd((int)cd)
.setLevelExp(levelExp)

.build();
}

Expand Down
31 changes: 21 additions & 10 deletions Src/Server/GameServer/src/main/java/com/game/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@
import com.game.manager.RoomManager;
import com.game.manager.StatusManager;
import com.game.models.Chat;
import com.game.proto.Message.ChatResponse;
//import com.game.proto.Message.ChatResponse;
import com.game.proto.Message.FollowListResponse;
import com.game.proto.Message.NCharacter;
import com.game.proto.Message.NItem;
import com.game.proto.Message.NRoom;
import com.game.proto.Message.NUser;
import com.game.proto.C2GNet.ChatResponse;
import com.game.proto.C2GNet.NRoom;
import com.game.proto.C2GNet.NUser;
import com.game.proto.Message.NUserStatusChange;
import com.game.proto.Message.NetMessageResponse;
import com.game.proto.Message.StatusNotify;
import com.game.proto.Message.TeamType;
import com.game.proto.Message.UnLockCharacter;
import com.game.proto.Message.UserStatus;
import com.game.proto.Message.UserStatusChangeResponse;
import com.game.proto.C2GNet.NetMessageResponse;
import com.game.proto.C2GNet.StatusNotify;
import com.game.proto.C2GNet.TeamType;
import com.game.proto.C2GNet.UnLockCharacter;
import com.game.proto.C2GNet.UserStatus;
import com.game.proto.C2GNet.UserStatusChangeResponse;

//import com.game.proto.Message.NRoom;
//import com.game.proto.Message.NUser;
//import com.game.proto.Message.NUserStatusChange;
//import com.game.proto.Message.NetMessageResponse;
//import com.game.proto.Message.StatusNotify;
//import com.game.proto.Message.TeamType;
//import com.game.proto.Message.UnLockCharacter;
//import com.game.proto.Message.UserStatus;
//import com.game.proto.Message.UserStatusChangeResponse;
import com.game.spring.DBUtil;

/**
Expand Down Expand Up @@ -151,7 +162,7 @@ public NUser.Builder infoBase(Integer charaId){
NRoom room = RoomManager.Instance.GetRoom(roomId);
if(room != null) {
builder.setBiFen(room.getBiFen()); //比分
boolean myResult = RoomManager.Instance.ExistUserRoom(id, room.getMyList()); //效验是否存在友队
boolean myResult = RoomManager.Instance.ExistUserRoom(id, room.getTeam1List()); //效验是否存在友队
builder.setTeamType(myResult ? TeamType.My : TeamType.Enemy); //队伍类型
builder.setRoomNum(RoomManager.Instance.GetRoomUserIdsNum(roomId)); //房间人数
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.util.StringUtils;

import com.game.proto.Message.NRoom;
import com.game.proto.Message.Result;
import com.game.proto.C2GNet.NRoom;
import com.game.proto.C2GNet.Result;
import com.game.util.GsonUtils;
import com.game.util.HttpUtil;
import com.game.util.PropertyUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.game.entity.Character;
import com.game.entity.User;
import com.game.proto.Message;
import com.game.proto.Message.ChatChannel;
import com.game.proto.Message.ChatMessage;
//import com.game.proto.Message.ChatChannel;
//import com.game.proto.Message.ChatMessage;
import com.game.proto.C2GNet.ChatChannel;
import com.game.proto.C2GNet.ChatMessage;
import com.game.util.TimeUtil;

import java.util.ArrayList;
Expand Down
Loading

0 comments on commit ef77ca2

Please sign in to comment.