1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using CommonLang;
- using CommonLang.Log;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Pomelo.DotNetClient
- {
- public class CommonMsg
- {
- private static Logger log = LoggerFactory.GetLogger("MPQDirver");
- private Dictionary<int, string> m_Msg;
- static private CommonMsg _Instance = null;
- static public CommonMsg GetInstance
- {
- get
- {
- if(_Instance == null)
- {
- _Instance = new CommonMsg();
- }
- return _Instance;
- }
- }
-
- CommonMsg()
- {
- m_Msg = new Dictionary<int, string>();
- }
- public int GetMsgID(string strMsg)
- {
- foreach(KeyValuePair<int ,string> kvp in m_Msg)
- {
- if(kvp.Value.Equals(strMsg))
- {
- return kvp.Key;
- }
- }
- return 0;
- }
- public string GetMsgStr(int msgId)
- {
- if(m_Msg.ContainsKey(msgId))
- {
- return m_Msg[msgId];
- }
- log.Error($"没有找到{msgId}对应的一串协议描述");
- return "";
- }
- public bool AddMsgID( short msgid, String msgname)
- {
- if(m_Msg.ContainsKey(msgid))
- {
- return false;
- }
- if(m_Msg.ContainsValue(msgname))
- {
- return false;
- }
- m_Msg.Add(msgid, msgname);
- return true;
- }
- }
- }
|