Home > other >  Photon server to connect to the database, storage and query
Photon server to connect to the database, storage and query

Time:09-19

I am a beginner,
Program of the client and the server can be connected, here is only part of the program, the other part of database operations,
I think this part of the procedure is the primary key of the database table, but I don't have any solution, turned to everyone a great god,
Public class roles
{
Public virtual int Id {set; The get; }//primary keys
Public virtual string Name {set; The get; }
Public virtual int Level {set; The get; }
Public virtual bool IsMan {set; The get; }
Public virtual string RolePrefabName {set; The get; }
Public virtual Users User {set; The get; }//foreign key
}

The class RoleMap: ClassMap
{
Public RoleMap ()
{
Id (x=& gt; X.I d). The Column (" Id ");//primary keys
The Map (x=& gt; X.N ame). The Column (" name ");
The Map (x=& gt; X.L evel). The Column (" level ");
The Map (x=& gt; X.I sMan). The Column (" isman ");
The Map (x=& gt; X.R olePrefabName). The Column (" roleprefabname ");
The References (x=& gt; X.U ser.) the Column (" userid ");//foreign key
The Table (" role ");
}
}
Public class RoleManager
{
Private static readonly ILogger log=ExitGames. Logging. That the LogManager. GetCurrentClassLogger ();

Public List GetRolesByUser Users (user)
{
Using (var session.=NHibernateHelper getSession ())
{
Using (var transaction=session. BeginTransaction ())
{
Var res=session. QueryOver (). The Where (x=& gt; X.U ser==user);
Transaction.Com MIT ();
The Info (" res RowCount ()="+ res. RowCount ());
Return (List) Res. List (a);//error
}
}
}

Public void AddRole (Role Role)
{
Log. The Info (role. The Name + "/" + role. Level + "/" + role. IsMan + "/" + role. RolePrefabName + "/" + role. The User. The UserName);
Using (var session.=NHibernateHelper getSession ())
{
Using (var transaction=session. BeginTransaction ())
{
The session. The Save (role);//error
Transaction.Com MIT ();
}
}
}
}

The class RoleHandler: defaulthandler
{
Private static readonly ILogger log=ExitGames. Logging. That the LogManager. GetCurrentClassLogger ();
RoleManager manager=null;
Public RoleHandler ()
{
Manager=new RoleManager ();
}

Public override OperationResponse OnHandlerMessage (OperationRequest request, BaiLaoDaPeer peer)
{
OperationResponse response=new OperationResponse ();
Dictionary The parameters=new Dictionary (a);
SubCode SubCode=ParameterTools. GetSubCode (request. The Parameters);
The parameters. The Add ((byte) ParameterCode SubCode, SubCode);

The switch (subCode)
{
Case SubCode. GetRole:
List RoleList=manager. GetRolesByUser (peer. LoginUser);
The foreach (var role1 roleList) in
{
Role1. User=null;
}
ParameterTools. AddParameter (parameters, ParameterCode RoleList, RoleList, true);
break;
Case SubCode. AddRole:
Role Role=ParameterTools. GetParameter (the request. The Parameters, ParameterCode Role, true);
Role. The User=peer. LoginUser.
Manager. AddRole (role);
//role through JsonMapper add to the parameters to the role. The User to empty,
//because JsonMapper resolution not, will go wrong, need other configuration,
Role. The User=null;
ParameterTools. AddParameter (parameters, ParameterCode Role, Role, true);
break;
}
The response. The Parameters=the Parameters;
The response. The ReturnCode=(short) ReturnCode. Success;
return response;
}

Public override OperationCode OpCode {
The get {return OperationCode. Role; }
}
}

Public class BaiLaoDaPeer: PeerBase
{
Private static readonly ILogger log=that the LogManager. GetCurrentClassLogger ();

Public Users LoginUser {get; set; }//store the current login user account
Public Role LoginRole {get; set; }
Public BaiLaoDaPeer (IRpcProtocol protocol, IPhotonPeer peer) : the base (protocol, peer)
{}
Protected override void OnDisconnect (PhotonHostRuntimeInterfaces DisconnectReason reasonCode, string reasonDetail)
{}
//call this function after the client requested to respond to client
Protected override void OnOperationRequest (OperationRequest OperationRequest, SendParameters SendParameters)
{
Defaulthandler handler=BaiLaoDaServer. Instances. GetHandlers (operationRequest. OperationCode);

If (handler!=null)
{
The Info (" handler from the operation code is isExit: "+ operationRequest. OperationCode);
OperationResponse response=handler. OnHandlerMessage (operationRequest, this);
SendOperationResponse (response, sendParameters);//to the client a response
}
The else {
The Info (" Can 't find handler from operation code: "+ operationRequest. OperationCode);
}
}
}
//========================================================================
Error message
The 2018-01-11 17:36:14, 502 [16] INFO BaiLaoDaServer. BaiLaoDaPeer [(null)] - handler from the operation code is isExit: 3
The 2018-01-11 17:36:14, 506 [16] INFO BaiLaoDaServer. DB. Managers. RoleManager [(null)] - SDFG/1/0/girl_stand/11 ytbai
The 2018-01-11 17:36:14, 514 [16] ERROR by Photon. SocketServer. PeerBase [(null)] - I got. Exceptions. GenericADOException: could not insert: [BaiLaoDaCommon. Model. Role] [SQL: insert INTO Role (name, level, isman, roleprefabname, userid) VALUES (?,?,?,?,?)] nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related