unity学习(15)——服务器组装(1)

1.新建好的c#项目如下:

文件夹中内容如下:

此时已经可以通过vs2022打开.sln文件,就可以打开项目了。

2.我们把逆向后(主程序)的内容的代码粘贴过去。有些逆向功底,很快可以定位到,服务器的入口函数ServerStart.start(10100);

其原始代码如下:

cs 复制代码
namespace GameServer.Hnalder
{
  internal class ServerStart
  {
    private static Socket server;

    public static void start(int port)
    {
      ServerStart.server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
      ServerStart.server.Bind((EndPoint) new IPEndPoint(IPAddress.Any, port));
      ServerStart.server.Listen(20);
      ServerStart.server.BeginAccept(new AsyncCallback(ServerStart.AcceptCallBack), (object) ServerStart.server);
    }

    public static void stop()
    {
      ServerStart.server.Dispose();
      ServerStart.server.Close();
    }

    private static void AcceptCallBack(IAsyncResult ar)
    {
      MyLog.form.textAdd("有客户端连接");
      try
      {
        Socket asyncState = (Socket) ar.AsyncState;
        Socket socket = asyncState.EndAccept(ar);
        Session session = new Session();
        session.socket = socket;
        LogicHandler.getInstance().sessionOpen(session);
        socket.BeginReceive(session.message, 0, session.message.Length, SocketFlags.None, new AsyncCallback(ServerStart.ReceiveCallBack), (object) session);
        asyncState.BeginAccept(new AsyncCallback(ServerStart.AcceptCallBack), (object) asyncState);
      }
      catch
      {
      }
    }

    private static void ReceiveCallBack(IAsyncResult ar)
    {
      Session asyncState = (Session) ar.AsyncState;
      try
      {
        int count = asyncState.socket.EndReceive(ar);
        if (count == 0)
        {
          MyLog.form.textAdd("有客户端断开连接");
          LogicHandler.getInstance().sessionClose(asyncState);
          return;
        }
        byte[] numArray = new byte[count];
        Buffer.BlockCopy((Array) asyncState.message, 0, (Array) numArray, 0, count);
        ServerStart.readMessage(asyncState, numArray);
      }
      catch (SocketException ex)
      {
        LogicHandler.getInstance().sessionClose(asyncState);
        asyncState.socket.Close();
        return;
      }
      asyncState.socket.BeginReceive(asyncState.message, 0, asyncState.message.Length, SocketFlags.None, new AsyncCallback(ServerStart.ReceiveCallBack), (object) asyncState);
    }

    public static void readMessage(Session session, byte[] bytes)
    {
      try
      {
        ByteArray byteArray = new ByteArray(bytes);
        int num1 = byteArray.ReadInt();
        int num2 = byteArray.ReadInt();
        int num3 = byteArray.ReadInt();
        int length = byteArray.ReadInt();
        string str = (string) null;
        if (length > 0)
          str = byteArray.ReadUTFBytes((uint) length);
        LogicHandler.getInstance().process(session, new SocketModel()
        {
          Type = num1,
          Area = num2,
          Command = num3,
          Message = str
        });
      }
      catch
      {
      }
    }
  }
}

直接沾进去,一共16个问题。

相关推荐
Web阿成1 小时前
3.学习webpack配置 尝试打包ts文件
前端·学习·webpack·typescript
雷神乐乐2 小时前
Spring学习(一)——Sping-XML
java·学习·spring
李雨非-19期-河北工职大2 小时前
思考: 与人交际
学习
哦哦~9212 小时前
深度学习驱动的油气开发技术与应用
大数据·人工智能·深度学习·学习
小木_.3 小时前
【python 逆向分析某有道翻译】分析有道翻译公开的密文内容,webpack类型,全程扣代码,最后实现接口调用翻译,仅供学习参考
javascript·python·学习·webpack·分享·逆向分析
Web阿成3 小时前
5.学习webpack配置 babel基本配置
前端·学习·webpack
LeonNo115 小时前
golang , chan学习
开发语言·学习·golang
南宫生5 小时前
力扣-数据结构-1【算法学习day.72】
java·数据结构·学习·算法·leetcode
索然无味io5 小时前
跨站请求伪造之基本介绍
前端·笔记·学习·web安全·网络安全·php